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;
WHERE
clauses is that the first excludes anyfoaf
that acted in anything together with Keanu, while the second one excludes anyfoaf
that only acted in movies with Keanu. (If there are more than one results for(movie)
, then it's sufficient that one offoaf
pass the condition in the second query to make it into the result: or, in other words, an actor may be match asfoaf
several times and only the instances that don't pass the condition are excluded.) – jjaderberg