我为自己设置了一个简单的例子,看看Neo4j如何处理涉及与自己有关系的节点的查询,我无法让Cypher给我所有的路径。
这是我的数据:
CREATE (A {name:'A'}), (B {name:'B'}), (C {name:'C'})
CREATE
(A)-[:REL]->(A),
(A)-[:REL]->(B),
(A)-[:REL]->(C),
(B)-[:REL]->(A),
(B)-[:REL]->(B),
(B)-[:REL]->(C),
(C)-[:REL]->(A),
(C)-[:REL]->(B),
(C)-[:REL]->(C)
这是我正在做的查询:
MATCH p = (x)-[:REL*1..3]->(y)
WHERE x.name='A' AND y.name='B' AND LENGTH(p) = 3
RETURN nodes(p)
我的预期结果是:
A, A, A, B
A, A, B, B
A, A, C, B
A, B, A, B
A, B, B, B
A, B, C, B
A, C, A, B
A, C, B, B
A, C, C, B
但我收到的是:
[(3 {name:"A"}), (2 {name:"B"}), (1 {name:"C"}), (2 {name:"B"})]
[(3 {name:"A"}), (1 {name:"C"}), (3 {name:"A"}), (2 {name:"B"})]
[(3 {name:"A"}), (1 {name:"C"}), (2 {name:"B"}), (2 {name:"B"})]
[(3 {name:"A"}), (1 {name:"C"}), (1 {name:"C"}), (2 {name:"B"})]
[(3 {name:"A"}), (3 {name:"A"}), (2 {name:"B"}), (2 {name:"B"})]
[(3 {name:"A"}), (3 {name:"A"}), (1 {name:"C"}), (2 {name:"B"})]
所以我没有得到的途径是:
A, A, A, B
A, B, B, B
A, B, A, B
有没有人有洞察力?
这是在控制台中:http://console.neo4j.org/?id=4srv4h
提前致谢。
答案 0 :(得分:1)
从A到A只有一个链接,所以它只能遍历A到A一次。这就是为什么你没有得到A,A,A(或B,B,B)......
同样,你消耗了A - > B关系第一次进入它们之间,所以你不能得到A,B,A,B。
最后,您可以执行:REL*3
并取消length(p) = 3
。