2

给定一个像这样的数据库:

    A       F
   / \       \
  B   C       G
 /
D

我想要 A 所涉及的所有关系的集合。这个查询是我能做的最好的,但返回 A 图中的所有节点对,并重复共享关系:

START start = node(A) 
MATCH (start)-[rel*]->(child)
RETURN rel, child;

如何最好地做到这一点?

4

1 回答 1

3

我需要这样的东西(由Peter Neubauer建议):

START s = node:node_auto_index(name="A") 
MATCH (s)-[:CHILD*0..]->(parent),        
      path=(parent)-[:CHILD]->(child),       
      (child)-[:CHILD*0..]->(leaf) 
WHERE NOT leaf-[:CHILD]->() 
WITH DISTINCT path AS path 
RETURN EXTRACT(n IN NODES(path): n.name)

在neo4j网站上草绘

更简洁的版本:

START s = node:node_auto_index(name="A") 
MATCH (s)-[:CHILD*0..]-( ss ),
      path = ( ss )-[:CHILD]->(child) 
WITH DISTINCT path AS path 
RETURN EXTRACT(n IN NODES(path): n.name)
于 2013-06-07T08:01:58.343 回答