Q:

neo4j - find nodes with strong relationship

I have in my graph places and persons as labels, and a relationship "knows_the_place". Like: 
(person)-[knows_the_place]->(place) 

A person usually knows multiple places.
Now I want to find the persons with a "strong" relationship via the places (which have a lot of "places" in common), so for example I want to query all persons, that share at least 3 different places, something like this (not working!) query:
MATCH
(a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(y:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(z:place)<-[:knows_the_place]-(b:person)
WHERE NOT x=y and y=z
RETURN a, b

How can I do this with neo4j Query?
Bonus-Question:
Instead of showing me the person which have x places in common with another person, even better would be, if I could get a order list like:
a shares 7 places with b
c shares 5 places with b
d shares 2 places with e
f shares 1 places with a
...
Thanks for your help!

A:

Here you go:
MATCH (a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person)
WITH a, b, count(x) AS count
WHERE count >= 3
RETURN a, b, count

To order:
MATCH (a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person)
RETURN a, b, count(x) AS count
ORDER BY count(x) DESC

You can also do both by adding an ORDER BY to the of the first query.
Keep in mind that this query is a cartesian product of a and b so it will examine every combination of person nodes, which may be not great performance-wise if you have a lot of person nodes.  Neo4j 2.3 should warn you about these sorts of queries.

