Reputation: 425
Im trying to find 'friend of friend' level recommendation in the given neo4j test data set, and I have come up with these two queries and Im not able to identify the bug in second query as it contains one extra node - '8' (Emil Eifrem). Please help me understand the difference. Thanks
1)
MATCH (keanu:Person {name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(f),
(f)-[:ACTED_IN]->()<-[:ACTED_IN]-(fof)
WHERE NOT (keanu)-[:ACTED_IN]->()<-[:ACTED_IN]-(fof) AND fof <> keanu
RETURN fof;
vs
2)
MATCH (keanu:Person {name:"Keanu Reeves"})-[:ACTED_IN]->(movie)<-[:ACTED_IN]-(f),
(f)-[:ACTED_IN]->(f_movies)<-[:ACTED_IN]-(fof)
WHERE NOT (movie)<-[:ACTED_IN]-(fof) AND fof <> keanu
RETURN fof;
Upvotes: 0
Views: 189
Reputation: 41676
The movie you are referring to in the second WHERE clause is one concrete movie that was matched in the MATCH clause before, so you only check against that single movie and not all potential movies between the fof and Keanu Reeves. That's why you filter out fewer people.
Upvotes: 1