Cypher查询:查找按关系属性过滤的两个节点之间的所有路径

Ori*_*ion 12 neo4j cypher

我将以下图表作为Neo4j图形数据库:

                           activates
                            (80 °F)
          (A)------------------------------------->(D)
           | \__                                _/->^
           |    \__  activates               __/    |
           |       \__(50 °F)             __/       |
           |          \__              __/          |             
           |             \__        __/             | 
activates  |                \__  __/                |
 (50 °F)   |                   \/                   | activates
           |                 __/\__                 | (50 °F)
           |    activates __/      \__              |
           |    (60 °F)__/            \__           |
           |        __/                  \__        |
           |     __/                        \__     |
           |  __/                              \_   |
           v /                                   \->|
          (B)------------------------------------->(C)
                           activates                          
                            (50 °F)
Run Code Online (Sandbox Code Playgroud)

每个关系都有一个属性,表示"激活"操作所需的温度.

我需要检索所有可用路径之间的(A)和(d)WHERE温度是沿着路径50°F.

输出应包括:

A -[:activates{temperature:'50'}]-> B -[:activates{temperature:'50'}]-> C -[:activates{temperature:'50'}]-> D

A -[:activates{temperature:'50'}]-> C -[:activates{temperature:'50'}]-> D
Run Code Online (Sandbox Code Playgroud)

但不是

A -[:activates{temperature:'80'}]-> D

A -[:activates{temperature:'50'}]-> B -[:activates{temperature:'60'}]-> D
Run Code Online (Sandbox Code Playgroud)

如何编写所需的Cypher查询?

提前致谢.

编辑1:我添加了另一个对角关系(B - [:激活{temperature:'80'}] - > D)以获得更清晰.

编辑2:我需要检索所有可用路径(A)和(d)之间WHERE温度相同的沿的路径,即:A - >乙- "ç - > d,A - "ç - > d, A - > D.

ulk*_*kas 17

START a=node({A}), d=node({D})
MATCH p=a-[r:ACTIVATES*..]-d
WHERE has(r.temperature) and r.temperature='50'
RETURN p;
Run Code Online (Sandbox Code Playgroud)

用其节点ID替换曲线括号(A,D)中的值

更新: 使用全部功能

START a=node(1), d=node(4) 
MATCH p=a-[r:ACTIVATES*..]-d 
WITH head(relationships(p))as r1,p //since the pointer r is a collection of rels we must declare a single relationship pointer
WHERE all(r2 in relationships(p) 
          where r2.temperature=r1.temperature) 
return p;
Run Code Online (Sandbox Code Playgroud)

  • 对于 neo4j 3.4,我使用了这个: MATCH p=(a:Database)-[r:PARENTS*..]-(d:Database) WHERE a.membershipID = 'H1001' and d.membershipID = "H12412" RETURN p; (2认同)