0
votes

Suppose tha I have the default database Movies and I want to find the total number of people that have participated in each movie, no matter their role (i.e. including the actors, the producers, the directors e.t.c.)

I have already done that using the query:

MATCH (m:Movie)<-[r]-(n:Person)
WITH m, COUNT(n) as count_people
RETURN m, count_people
ORDER BY count_people DESC
LIMIT 3

Ok, I have included some extra options but that doesn't really matter in my actual question. From the above query, I will get 3 movies.

Q. How can I enrich the above query, so I can get a graph including all the relationships regarding these 3 movies (i.e.DIRECTED, ACTED_IN,PRODUCED e.t.c)?

I know that I can deploy all the relationships regarding each movie through the buttons on each movie node, but I would like to know whether I can do so through cypher.

1

1 Answers

1
votes

Use additional optional match:

MATCH (m:Movie)<--(n:Person)
WITH m, 
     COUNT(n) as count_people 
ORDER BY count_people DESC 
LIMIT 3
OPTIONAL MATCH p = (m)-[r]-(RN) WHERE type(r) IN ['DIRECTED', 'ACTED_IN', 'PRODUCED']
RETURN m, 
       collect(p) as graphPaths,
       count_people 
ORDER BY count_people DESC