简体   繁体   English

如何获得路径上节点之间的所有关系

[英]How do I get all relationships between nodes on a path

I am trying to follow a certain relationship type and return all the nodes and (other) relationships on that path but not to follow paths through nodes that are not part of the path. 我正在尝试遵循某种关系类型,并返回该路径上的所有节点和(其他)关系,但不遵循通过不属于该路径的节点的路径。

Below is the live query that I have set up to demonstrate. 以下是我设置的实时查询。

http://console.neo4j.org/?id=b6sxoh http://console.neo4j.org/?id=b6sxoh

In the example I do not want the relationship through B->E->C to be included in the results because there is no 'depends_on' relationship between them. 在示例中,我不希望通过B-> E-> C的关系包含在结果中,因为它们之间没有“ depends_on”关系。

Below is one of my many attempts... (also in the console). 以下是我的许多尝试之一...(也在控制台中)。

START me=node:node_auto_index(name='A')
MATCH p=me-[d:depends_on*]->others 
WITH me,others 
MATCH p=me-[r*]-others 
RETURN DISTINCT relationships(p);

I would love some help please! 我希望有帮助!

One way to do this is to iterate through each pair of nodes on the matched path for the pattern "p=me-[d:depends_on*]->others", and find any other relationships between them. 一种实现方法是遍历模式“ p = me- [d:depends_on *]->其他”的匹配路径上的每对节点,并找到它们之间的任何其他关系。

START me=node:node_auto_index(name='A')
MATCH me-[:depends_on*0..]->(previous)-[:depends_on]->last
With previous, last
Match previous-[r]-last
Where type(r) <> 'depends_on'
Return r

Since each matched path for the pattern "me-[d:depends_on*]->others" is augmented with a new relationship as the last relationship, to iterate through all the relationships on the matched path is to iterate through each last relationship on the matched paths. 由于模式“ me- [d:depends_on *]-> others”的每个匹配路径都增加了新的关系作为最后的关系,因此要遍历匹配路径上的所有关系就是要遍历模式中的每个最后关系。匹配的路径。 So for each matched path, we capture the start node and the end node of the last relationship as "previous" and "last" and then find the relationships "r" between them, filter "r" with the "Where" clause based on the type of the relationship r, return only those relationships r that are not of the type "depends_on". 因此,对于每个匹配的路径,我们将最后一个关系的开始节点和结束节点捕获为“上一个”和“最后一个”,然后找到它们之间的关系“ r”,并根据以下条件使用“ Where”子句过滤“ r”关系r的类型,仅返回不属于“ depends_on”类型的那些关系r。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得从一个节点到另一个节点的路径,包括所有其他节点以及它们之间涉及的关系 - How to get a path from one node to another including all other nodes and relationships involved in between 如何使用Cypher获得两个节点之间相同关系的数量 - How do i get number of same relationships between two nodes with Cypher 获取所有有关系的节点 - Get all nodes with relationships 如何显示 neo4j 中的所有节点和两个节点之间的关系? - How can i display the all nodes and relationships between two nodes in neo4j? 如何在neo4j中从起始节点获取所有可到达的节点(以及它们之间的所有关系?) - how to get all reachable nodes from a starting node (and optionally all relationships between them?) in neo4j 如何确保两个节点之间的路径贯穿中间节点的所有连接? - How do I make sure a path between two nodes runs through all the connections of an intermediate node? 计算2个节点之间的所有关系 - Compute all the relationships between 2 nodes Neo4j,获取一组节点之间的所有关系 - Neo4j, get all relationships between a set of nodes Neo4j:获取一组节点之间的所有关系 - Neo4j: Get all relationships between a set of nodes 如何在Neo4j中对两个节点之间的关系数量创建约束 - How do I create a constraint on the number of relationships between two nodes in Neo4j
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM