2017-07-02 64 views
1

刪除子我有以下圖表 graph layout暗號 - 從結果

正如你可以看到,圖中的下列關係:

  1. (u::4)-[ADDED_RESOURCE]->(:resource)<-[ADDED_RESOURCE]-(u::3) \\ u::4, u::3 are the ids of the nodes

  2. (u::4)-[UNLINK]->(u::3)

我使用APOC遍歷像這樣的圖形:

MATCH (u:user {id:"u::1"} 
CALL apoc.path.expandConfig(u,{minLevel:1,maxLevel:6,bfs:true,uniqueness:"NODE_PATH",labelFilter:">resource"}) YIELD path 
with u, path, filter(n in nodes(path) where n:resource) as resources 
unwind resources as resource 
MATCH (rus:user)-[]->(resource) 
RETURN distinct rus.id 

這將返回所有通過它的相關資源,以節點u::1相關u::X節點。

因爲u::4u::3是取消鏈接,我想遍歷忽略該連接,並不會返回與u::3有關的子圖。因此,而不是返回u::4, u::3, u::2, u::5,它應該只返回u::4

有沒有辦法告訴APOC在遍歷時忽略它們之間有一定關係的節點?

回答

2

我不認爲apoc.path.expandConfig將允許您忽略關係類型列表,但它會遵循正面表達的關係類型。並且可以選擇使用<,>進行定單。

MATCH (u:user {id:"u::1"} 
CALL apoc.path.expandConfig(u 
    { 
    minLevel:1, 
    maxLevel:6, 
    bfs:true, 
    uniqueness:"NODE_PATH", 
    labelFilter:">resource", 

    // add relationship filter to folow only relationships that are included 
    relationshipFilter: 'ADDED_RESOURCE|OTHER_TYPE|...' 
}) YIELD path 
with u, path, filter(n in nodes(path) where n:resource) as resources 
UNWIND resources as resource 
MATCH (rus:user)-[]->(resource) 
RETURN distinct rus.id 
+0

謝謝,但如果我想同時維護'UNLINK'和'ADDED_RESOURCE'鏈接,我會遇到問題。無論「UNLINK」關係如何,它仍會返回所有連接的用戶。 –