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:

http://nigelsmall.com/zen


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -