Reputation: 20670
I am beginning to use Neo4J and to get used to Cypher. My graph contains 3 types of entities: actors, movies, categories
The edges are:
I was able to write a query that display the topics of all the movies of an actor .
A demo of the graph and the query is set up in the neo4j console http://console.neo4j.org/?id=sm07j5
Now, I want to write a query that retrieves all the topics of an actor and then the actors that participated in a movie of any of these topics categories: Is it possible to do it with a single query? Or do I have to store first the top categories in a variable?
Does Cypher support variable definition from query results?
Upvotes: 0
Views: 187
Reputation: 478
If I correctly understand your requirement to "query that retrieves the top categories of an actor and then the actors that participated in a movie of any of these top categories" this would be simple answer if there were no this "top categories".
MATCH (Robin: Actor {name: 'Robin Williams'})-[:ACTS_IN]->(m:Movie)-[:IS_ABOUT]->(t:Topic)
WITH t MATCH (t:Topic)<-[:IS_ABOUT]-(r:Movie)<-[:ACTS_IN]-(a:Actor)
RETURN a, COLLECT(t)
Above query result:
(2:Actor {name:"Demi Moore"}) [(7:Topic {name:"Teenagers"})]
(1:Actor {name:"Tom Cruise"}) [(7:Topic {name:"Teenagers"})]
(3:Actor {name:"Tom Hanks"}) [(8:Topic {name:"School"})]
(0:Actor {name:"Robin Williams"}) [(8:Topic {name:"School"}), (7:Topic {name:"Teenagers"})]
As @InverseFalcon commented, you did not provide any info on how categories should be valued and ordered...
Upvotes: 1