Hello dear community!
the graph of my database has a hierarchical tree-like structure with subgraphs connected to the leafs. Now I want to match all nodes and edges in one of these subgraphs, which have arbitrary depth, labels, properties and edge direction (but there is certainly no label equal to the leafs label). For this reason it is necessary to match such a subgraph recursively. The only information given is the leaf and the node connected to the leaf in the parent hierarchy level. So let's assume one path in the tree-like structure looks as following:
(:Project {name:"Project1"})-->(:Submission {name:"Submission"})-->......
where ..... denotes the whole subgraph I want to match. The submission node would be the leaf in this case.
I've tried a lot, but in the following I will show the two solutions which seem to me best by now with a few thoughts:
MATCH (:Project {name:"Project1"})-->(s:Submission {name:"Submission"})-[*]-(x)
WHERE NOT x:Project AND NOT x:Submission
RETURN s,x
the WHERE clause is necessary as (I guess) the query will otherwise return to the submission node and recursively search the whole graph. Nevertheless, this query does not terminate, although the subgraph has only about 200 graphs. Very interesting is, that if I specifiy a depth, such as [*1..12] the query will terminate and deliver the same result as for [*1..13]. I can't explain myself why the limitless recursion wouldn't work then.
The other query I tried uses a procedure:
'''MATCH (:Project {name:"Project1"})-->(s:Submission {name:"Submission"})
CALL apoc.path.subgraphAll(s, {labelFilter: "-Submission-Project"}) yield nodes
return s, nodes'''
This query won't terminate as well... Is there anything I'm missing out here?
Thanks a lot!
Best wishes,
Adrian