[英]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.