简体   繁体   中英

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

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.

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.

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. 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM