Friend recommendation

(于鹏飞) #1

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?

(Ashwin) #2

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 

For more details on how variable propagation works:

(于鹏飞) #3

It show

Expecting argument name. Got: lex.Item [12] “(”

shall I upgrade to 0.8?

(Ashwin) #4

Try with nightly binary (from master)

(于鹏飞) #5

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.

(Ashwin) #6

That is covered by @filter(not uid(me, fr)).

(于鹏飞) #7

So many thanks, I will try it now.

(system) #8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.