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

从neo4j图中查找所有子连通子图,neo4j,cypher,Neo4j,Cypher,在多次尝试并在网上到处寻找相关问题都没有成功后,iv'e决定在这里提问-我希望你能提供帮助 我的问题是->我试图在neo4j数据库中找到所有未连接的子图。这里的主要问题是,从连接集中的给定节点沿单个方向进行遍历不会始终遍历连接集中的所有节点->它只会遍历查询中某个方向的节点,如下所示: match (a:TempNode)-[r*]->(n) where NOT (a)<-[:LINKED|LINKED2]-(:TempNode) return distinct(a.Lineage+

在多次尝试并在网上到处寻找相关问题都没有成功后,iv'e决定在这里提问-我希望你能提供帮助

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

match (a:TempNode)-[r*]->(n)
where NOT (a)<-[:LINKED|LINKED2]-(:TempNode)
return distinct(a.Lineage+collect(distinct(n.Lineage)))
如果我放入一个过滤器来获得某个特定的集合,可能会起作用,但我不能将过滤器放入其中,因为我想要所有的子连接集合,这将永远运行,我有约2000个集合,其中的节点数量约为40000个

有什么建议可以帮助我有效地解决这个问题吗

我正在尝试从现有的图中创建一个新的图,其中所有集都从一个节点(例如id最小的节点)开始,只有一个方向,直到id最高的节点,在本质上,这意味着为每个次级连接的组创建一个有序的集合,但无法实现

如有任何建议,将不胜感激

谢谢


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

使用Apoc程序()

要获取对遍历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)
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)
匹配(cs:SomeLabel)-[:LINKED]->(:SomeLabel)
非(cs)使用Apoc程序()

要获取对遍历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)
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)
匹配(cs:SomeLabel)-[:LINKED]->(:SomeLabel)

哪里不(cs)没关系,解决了:)看起来是个不错的解决方案!为了结束这个问题,你能把答案复制粘贴到一个答案上并接受它吗?这样,如果你的问题与其他人的问题相关,它将清楚地表明问题已经得到了回答。如果不考虑,链接到它(如右侧相关问题列表中的链接)会使它看起来像一个没有给出答案的未回答问题。当然:)发布了答案太棒了!确保也接受你的答案(分数下面的复选标记)