Hi , i have this query for recommendation nodes. {
find as var(func: eq(first_name,"mehrdad")) {
sc as math(1)
fr as follow {
follow {
fscore as math(sc)
}
}
}
recommendationProfile(func: uid(fscore), orderdesc: val(fscore), first: 10) @filter(not uid(find, fr)) {
id
first_name
}
}
i want set a filter for this query .
filter is :
when find users for recommend to a user , filter users that have a experience common with the user (example: “mehrdad”)
experience is a edge that user(mehrdad) has a connect to this.this picture is a sample data for this recommend.
the green edge is experience edge and blue edge is follow edge.
in this data all 2 experience edge is same node.i don’t know how to write this .
thank you for help
{
find as var(func: eq(first_name,"مهرداد")) {
sc as math(1)
fr as follow {
follow {
fscore as math(sc)
}
}
}
recommendationProfile(func: uid(fscore), orderdesc: val(fscore), first: 10) @filter(not uid(find, fr)) {
id
first_name
}
}
Just posted a blog post about this kind of use cases
Normally you should use the reverse edge of follow
relationship in the nested block.
follow predicate must have the @reverse index.
{
find as var(func: eq(first_name,"مهرداد")) {
sc as math(1)
fr as follow {
~follow @filter(not uid(find)) {
fscore as math(sc)
}
}
}
recommendationProfile(func: uid(fscore), orderdesc: val(fscore), first: 10) {
id
first_name
}
}
Unless there is something I did not get in your use case.
Now you want to add a constraint on the person. You can do that with @cascade directive to find only the nodes matching a patterns. In your case the person must have at least one relationships with an Experience nodes from ‘find’.
So something like that should work for you , assuming that experience
is the relationship between a user and an Experience
node.
{
find as var(func: eq(first_name,"مهرداد")) {
sc as math(1)
find_experience as experience # keep the set of experiences for user A
fr as follow {
~follow @filter(not uid(find)) @cascade {
# with @cascade all nested levels must have at least one data
experience @filter( uid(find_experience)) { }
fscore as math(sc)
}
}
}
recommendationProfile(func: uid(fscore), orderdesc: val(fscore), first: 10) {
id
first_name
}
}
with @cascade, you only get the nodes with a non empty sub-graph
experience @filter( uid(find_experience)) { }
which means at least one experience in common. I don’t think you need the {} at all.
Let me know if it is the result you wanted.