![](/img/trans.png)
[英]How to get a path from one node to another including all other nodes and relationships involved in between
[英]How do I get all relationships between nodes on a path
我正在嘗試遵循某種關系類型,並返回該路徑上的所有節點和(其他)關系,但不遵循通過不屬於該路徑的節點的路徑。
以下是我設置的實時查詢。
http://console.neo4j.org/?id=b6sxoh
在示例中,我不希望通過B-> E-> C的關系包含在結果中,因為它們之間沒有“ depends_on”關系。
以下是我的許多嘗試之一...(也在控制台中)。
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);
我希望有幫助!
一種實現方法是遍歷模式“ 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
由於模式“ me- [d:depends_on *]-> others”的每個匹配路徑都增加了新的關系作為最后的關系,因此要遍歷匹配路徑上的所有關系就是要遍歷模式中的每個最后關系。匹配的路徑。 因此,對於每個匹配的路徑,我們將最后一個關系的開始節點和結束節點捕獲為“上一個”和“最后一個”,然后找到它們之間的關系“ r”,並根據以下條件使用“ Where”子句過濾“ r”關系r的類型,僅返回不屬於“ depends_on”類型的那些關系r。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.