Hello everyone,
How to do friend recommendation with dgraph? What I want is tell the user, you and him have 10(some number) Mutual Friend, so you may like to add him as a friend.
I want to show a list of recommendation to every user, how can I do it?
Hey @yupengfei
You can do something as follows
{
me as var(func: uid(<userid>)) {
sc as math(1) # Give a score of 1 to the user
fr as friend {
friend {
fscore as math(sc) # This will be number of common friends
}
}
}
# Get top ten people with highest score
TopRecommendations(func: uid(fscore), orderdesc: val(fscore), first: 10) @filter(not uid(me, fr)) { # Remove the user and his friends
name
}
}
For more details on how variable propagation works: https://open.dgraph.io/post/recommendation/
1 Like
It show
Expecting argument name. Got: lex.Item [12] “(”
shall I upgrade to 0.8?
Try with nightly binary (from master)
And how can I filter the guys that already been friend.
A <friend> B
B <friend> C
A <friend> C
surely I do not want to recommend C to A, even he is friend of friend because he is friend already.
That is covered by @filter(not uid(me, fr))
.
So many thanks, I will try it now.
1 Like
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.