2017-07-02 63 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”关系如何,它仍会返回所有连接的用户。 –