Cypher help


(Joe) #1
MATCH (:Institute {instituteName:'aaa school'}) <-[r:WORKED_IN]-(:Author)<-[:WRITTEN_BY]-(p:Paper)-[:WRITTEN_BY]->(:Author)-[:WORKED_IN]->(:Institute {instituteName: 'bbb school'}) 
RETURN p LIMIT 25

Anyone knows how to rewrite this code such that i can obtain the paper written together by authors from more schools?


(Ameyasoft) #2

Try this:

MATCH (a1:Author)-[r:WORKED_IN]->(:Institute {instituteName:'aaa school'})
MATCH (a2:Author)-[:WORKED_IN]->(:Institute {instituteName: 'bbb school'})
WITH a1, a2

MATCH(p:Paper)-[:WRITTEN_BY]->(a1)
OPTIONAL MATCH (p)-[:WRITTEN_BY]->(a2)

RETURN p LIMIT 25;


(Michael Black) #3

Could you use a recursion strategy? Here's an example query on the Movie Graph that will search 2 levels deep. m:Movie would be the paper, p:Person would be your author, m2:Movie would be your school in your model.

match (m:Movie {title: "A Few Good Men"})-[*1..2]-(p:Person)-[]-(m2:Movie)
return *