In a simple movielens-like scenario I want to get all the people that gave the same ratings to some of the movies I rated.
I first tried to achieve this by using facets but, since I cannot use variables in facets filters, I ended up adding a comment to an issue on github about this (Allow value variables in facet filters · Issue #2406 · dgraph-io/dgraph · GitHub). Since I’m a beginner with DGraph I wanted to know if there is another way to get this by using facets instead of the one I described in the issue.
In the meanwhile I tried another way using a “Rating” node to join people to movies. This isn’t working either, most probably because I’m not getting it right with variables and filters.
Can someone help me with this please? Here is the sample schema, data and query:
################
# Schema
<name>: string @index(exact, term) @upsert .
<rated>: [uid] @reverse .
<movie>: uid @reverse .
<rate>: int .
type Person {
name
rated
}
type Rating {
movie
rate
}
type Movie {
name
}
#################
# Data
{
set {
#Movies
_:t <dgraph.type> "Movie" .
_:t <name> "Movie 1" .
#People
_:a <dgraph.type> "Person" .
_:a <name> "Me" .
_:b <dgraph.type> "Person" .
_:b <name> "P1" .
_:c <dgraph.type> "Person" .
_:c <name> "P2" .
#Ratings
_:a1 <dgraph.type> "Rating" .
_:a1 <movie> _:t .
_:a1 <rate> "5" .
_:a <rated> _:a1 .
_:b2 <dgraph.type> "Rating" .
_:b2 <movie> _:t .
_:b2 <rate> "3" .
_:b <rated> _:b2 .
_:c3 <dgraph.type> "Rating" .
_:c3 <movie> _:t .
_:c3 <rate> "5" .
_:c <rated> _:c3 .
}
}
#################
# Load scenario
{
scenario(func: type("Person")) @filter(eq(name,"Me")) @ignorereflex {
name
rated {
rate
movie {
name
~movie {
rate
~rated {
name
}
}
}
}
}
}
#First try: Get people who rated at least one movie as I did
### Fails with error: "Message: : eq expects atleast 1 argument."
{
b(func: type("Person")) @filter(eq(name, "Me")) @ignorereflex @cascade {
name
rated {
rate1 as rate
movie {
name
with_ratings: ~movie @filter(eq(rate, val(rate1))) {
rate
people: ~rated {
name
}
}
}
}
}
}
#Second try: Get people who rated at least one movie as I did
### Fails: empty result set
{
b(func: type("Person")) @filter(eq(name, "Me")) @ignorereflex @cascade {
name
rated {
rate1 as rate
movie {
name
with_ratings: ~movie @filter(eq(rate2, val(rate1))) {
rate2: rate
people: ~rated {
name
}
}
}
}
}
}