密码查询:查找通过关系属性过滤的两个节点之间的所有路径 [英] Cypher query: Finding all paths between two nodes filtered by relationship properties

查看:135
本文介绍了密码查询:查找通过关系属性过滤的两个节点之间的所有路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following graph as a Neo4j graph database:

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

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

Each relationship has a property denoting the required temperature for the 'activates' action.

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

I need to retrieve all the available paths between (A) and (D) WHERE the temperature is 50 °F along the path.

输出应包括:

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

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

但不是

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

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

如何编写所需的Cypher查询?

How do I write the required Cypher query?

谢谢.

为了更加清晰起见,我添加了另一个对角线关系(B-[:activates {temperature:'80'}]-> D).

Edit 1: I added another diagonal relationship (B -[:activates{temperature:'80'}]-> D) for more clarity.

我需要检索(A)和(D)之间的所有可用路径 在哪里温度为沿路径相同,即:A-> B-> C-> D,A-> C-> D,A-> D.

Edit 2: I need to retrieve all the available paths between (A) and (D) WHERE the temperature is the same along the path, i.e: A -> B -> C -> D, A -> C -> D, A -> D.

推荐答案

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

用括号ID替换括号(A,D)中的值

substitute the values in the curved brackets (A,D) with their node IDs

更新: 使用功能全部

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;

这篇关于密码查询:查找通过关系属性过滤的两个节点之间的所有路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆