Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-09-2018 09:18 AM
MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
Without anything else, couldnt all the above indicated nodes be the same node? In other words, "keanu", "c"and "coc" could all refer to Keanu Reeves, for example. Is this correct?
Also, if we specified the following:
MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
WHERE keanu <> c
All we would be guaranteeing is that keanu and c are not equal, so therefore coc and keanu could be right? On that note, wouldnt the following also have a similar reasoning:
MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
WHERE keanu <> coc
Only keanu and coc are not equal, but keanu and c could be equal.
Couldn't the same be said about this query below, in that coActor could refer to keanu?
MATCH (keanu:Person)-[:ACTED_IN]->(movie:Movie),
(coActor:Person)-[:ACTED_IN]->(movie)
WHERE keanu.name = 'Keanu Reeves'
RETURN DISTINCT coActor.name;
09-09-2018 11:35 AM
It's important to understand one specific aspect of a path in Cypher: the very same relationship will never be used multiple times. Otherwise this would allow for infinite recursion.
That said, in your example c
is never keanu
- unless there are more than one :ACTED_IN
relationships between the same actor and same movie.
09-09-2018 11:38 AM
How about the coActor?
09-09-2018 11:46 AM
coactor and keanu can be the same if the movie nodes ( the ones referred to as ()
in your example are different.
Example:
Keanu coacted with Laurence Fishburne coacting in all 3 movies of the matrix trilogy
So a path would be:
(keanu)-[:ACTED_IN]->(matrix)<-[:ACTED_IN]-(laurence)-[:ACTED_IN]->(matrix revolutions)<-[:ACTED_IN]-(keanu)
q.e.d.
09-09-2018 12:46 PM
I had several examples because I wanted to understand the logic in different contexts. No reason for the q.e.d. 🙂 thanks.
All the sessions of the conference are now available online