Social Network Graph Example from Diaspora
Sarah Mei recently wrote a blog post describing how she and her colleagues modeled a collection of TV shows and a social network. A few of us at Neo felt strongly that these domains were very graphy in nature.
We wanted to see if our intuition was right (we love the Diaspora project and extend our help to you) and so with the help of Cypher, created a mini version of each of the domains that Sarah described.
This is the second of two GraphGists that are part of the response to Sarah’s blog post. If you would like to quickly jump to the first one that details the TV Show Graph data model, you can find it here: TV Show Graph Diaspora example
Social Network Setup
Now let’s write some queries!
We’ll start with one to find the posts made by Rachel’s friends:
MATCH (u:User)-[:FRIEND]-(f)-[:POSTED]->(post)
WHERE u.name = "Rachel Green"
RETURN f.name AS friend, post.text as content
Our next query might be a slight variation on this to collect the people who have liked a post:
MATCH (u:User)-[:FRIEND]-(f)-[:POSTED]->(post)<-[like:LIKED]-(liker)
WHERE u.name = "Rachel Green"
RETURN f.name AS friend, post.text as content, COLLECT(liker.name) as liked_by
A third query could collect all actions on a post, be they likes or comments:
MATCH (u:User)-[:FRIEND]-(f)-[:POSTED]->(post)<-[a:LIKED|:COMMENTED]->(person)
WHERE u.name = "Rachel Green"
RETURN f.name AS friend, post.text AS content,
COLLECT({ text: a.text, person: person.name, action: TYPE(a)}) AS actions
Is this page helpful?