我为自己设置了一个简单的示例,以了解 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
提前致谢。