cypher - Finding friends with 2 common friends in Neo4j -
given relationship:
(p1:person)-[:friend]->(p2:person)
is there way find pairs of people eg. (p1,p2) have 2 or more friends in common?
this should it:
match (p1:person)-[:friend]-(friend:person)-[:friend]-(p2:person) p1, p2, count(friend) friend_count friend_count >= 2 return p1, p2, friend_count
but keep in mind cartesean product of person
nodes, collection grows, query have @ every combination of every pair of people. that's fine long don't care running query lot / running fast.
also note common style labels uppercamelcase
. see pretty style guide:
Comments
Post a Comment