Reputation: 335
This example from documentation returns the commonMovies given a list of actors in which they all acted in.
https://neo4j.com/developer/kb/performing-match-intersection/#_use_apoc_to_intersect_result_lists
Instead of returning just 1 row for the common movies, how can I return the actor name as well for example
Keanu Reeves, [Movie1,Movie2,Movie3]
Hugo Weaving, [Movie1,Movie2,Movie3]
Emil Eifrem, [Movie1,Movie2,Movie3]
The common movies list would be same for each row, it wouldn't make sense in this case, but I abstracted my problem down to this
Upvotes: 0
Views: 291
Reputation: 2237
Maybe, you could unwind the names
list at the end to turn the names into individual rows. When doing so, you need to pass names
to each WITH
clause.
WITH ['Keanu Reeves', 'Hugo Weaving', 'Emil Eifrem'] as names
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name in names
WITH names, p, collect(m) as moviesPerActor
WITH names, collect(moviesPerActor) as movies
WITH names, reduce(commonMovies = head(movies), movie in tail(movies) |
apoc.coll.intersection(commonMovies, movie)) as commonMovies
UNWIND names as name
RETURN name, commonMovies
Upvotes: 1