简体   繁体   中英

py2neo recursive matching

I'm playing with py2neo and now the I'm looking for the most convenient manner to find all children of a specific node using recursion.

What I'm looking for is the following idea:

MATCH (:LabelA {id:"C"})-[:to*]->(m:LabelA) RETURN n;

This is what it would look like in cypher. I know this query can be run with graph.run() and by passing this query. But I was wondering if somebody knows if it is possible using the graph.match() code?

Finding the first node is possible with:

sNode = graph.nodes.match(id="C").first()
firstNode = graph.match((sNode, ), r_type="to")

and I'm hoping there is a construct such as (I tried this and this does not work:) ):

sNode = graph.nodes.match(id="C").first()
nodesFound = graph.match((sNode, ), r_type="to*")
#do something with nodesFound

that would return all recursively found nodes in a list or so.

Does anyone have experience with this?

There is no way to do this with the matchers. You'll have to use Cypher.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM