Question

I am trying to make a social network. I am using Neo4j to show relations between entities like different users, users and locations like cities, users and groups like music, etc. I am making friends suggestion like in Facebook the result is judged on many criteria, say we want to suggest friend for user1 and trying to judge user2 for the suggestion ,the criteria are:

  1. does user2 live near user1
  2. what are the common liking between user2 and user1
  3. how many mutual friends user2 and so on...

There are different point for all the above criteria and at last average is done and the higher the average the higher the rank of user2 in friends suggestion list.

I think I got idea of friends suggestion but I want to implement it in neo4j via normal search query in cypher and get top 10 friend suggestion.

My questions:

  1. Can it be done or I have to use plugins like ElasticSearch?

  2. if yes, can you point me to any example or document

Was it helpful?

Solution

Something like:

MATCH (u:User {login:{login}})-[:LIVES_IN]->(location)
MATCH (u)-[:FRIEND]->(friend)<-[:FRIEND]-(other)
WITH u,location,other,count(*) as friends
MATCH (u)-[:LIKED]->(thing)<-[:LIKED]-(other)
WITH u,location,other,friends, count(*) as things
MATCH (other)-[:LIVES_IN]->(location)
RETURN u,other,friends+things as score
ORDER BY score DESC
LIMIT 10

OTHER TIPS

For sure, this can be done with neo4j without use of ElasticSearch, just make a good use of labels.

For "does user2 live near user1", maybe you'll need the neo4j spatial plugin.

Some examples regarding social graphs, you'll sure find some more by looking in google.

http://docs.neo4j.org/chunked/stable/data-modeling-examples.html

Chris

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top