首页 文章

从neo4j图中查找所有子连接子图

提问于
浏览
0

尝试多次尝试并在网上随处查找相关问题不成功后,我决定在这里问一下 - 我希望你能提供帮助 .

我的问题是 - >我试图在neo4j数据库中找到所有未连接的子图 . 这里的主要问题是,从连接集中的给定节点向单个方向遍历,不会全部遍历连接集中的所有节点 - >它只会遍历查询中某个方向的节点:

match (a:TempNode)-[r*]->(n)
where NOT (a)<-[:LINKED|LINKED2]-(:TempNode)
return distinct(a.Lineage+collect(distinct(n.Lineage)))

(假设第二个'Where'条件是集合的假设'起始'节点) .

问题是,我的图表填充了连接集,如下所示:
Conncted set Example

所以,正如您所看到的,它有许多节点,它们之间的边缘方向不一致 .

运行无向的查询,如:

match (a:MetasetFeature)-[r*]-(n)
return a,collect(distinct(n))

如果我放入一个过滤器以获得一些特定的设置,但我不能把过滤器放在里面,因为我想要所有我的子连接集,并且将永远运行,并且我有〜2000个这些集合,具有一定数量的节点~40000 .

任何建议如何有效地解决这个问题?

我试图想出一种从现有图形创建新图形的方法,其中所有集合都将从一个节点(例如具有最小id的节点)开始,并且只有一个方向,直到具有最高节点的节点id,在essense中意味着从每个子连接组创建一个有序集但无法实现它 .

任何建议将不胜感激 .

谢谢 !

*编辑:没关系,解决了它:) .

使用了Apoc程序(https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases

要访问遍历API,并使用此查询解决问题,如果其他人需要它:

MATCH (cs:SomeLabel)-[:LINKED]->(:SomeLabel)
where NOT (cs)<-[:LINKED]-(:SomeLabel)
CALL apoc.path.expandConfig(cs,       {relationshipFilter:"LINKED",uniqueness:"NODE_GLOBAL",bfs:false}) YIELD path
WITH cs.Lineage as source, path 
unwind extract(x in nodes(path) | x.Lineage) as node
with source, collect(distinct(node)) as set 
unwind set as setMember
with source,setMember
order by setMember
with source,collect(setMember) as orderedSet
return distinct(orderedSet)

1 回答

  • 0

    使用了Apoc程序(https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases

    要访问遍历API,并使用此查询解决问题,如果其他人需要它:

    MATCH (cs:SomeLabel)-[:LINKED]->(:SomeLabel)
    where NOT (cs)<-[:LINKED]-(:SomeLabel)
    CALL apoc.path.expandConfig(cs,       {relationshipFilter:"LINKED",uniqueness:"NODE_GLOBAL",bfs:false}) YIELD path
    WITH cs.Lineage as source, path 
    unwind extract(x in nodes(path) | x.Lineage) as node
    with source, collect(distinct(node)) as set 
    unwind set as setMember
    with source,setMember
    order by setMember
    with source,collect(setMember) as orderedSet
    return distinct(orderedSet)
    

相关问题