Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Path 只需要跨多个路径的公共节点-Neo4j Cypher_Path_Neo4j_Cypher_Intersect - Fatal编程技术网

Path 只需要跨多个路径的公共节点-Neo4j Cypher

Path 只需要跨多个路径的公共节点-Neo4j Cypher,path,neo4j,cypher,intersect,Path,Neo4j,Cypher,Intersect,sMy Cypher查询查找多个起始节点的公共子节点。每个路径仅提取并返回其节点id,从而在每个路径中产生数百行。参见p1和p2示例(仅显示3行和两个起点) 我想要的是在查询期间在cypher中相交路径,这样以后就不必这样做了。在php中,我将使用以下方法进行迭代: $result = array_intersect($p1,$p2); 这将从上面的示例返回9,3,因为它们是所有路径共享的唯一公共节点。有没有办法在Cypher中执行此操作,这样我就不会返回数百行 谢谢 我相信这将满足您的需要

sMy Cypher查询查找多个起始节点的公共子节点。每个路径仅提取并返回其节点id,从而在每个路径中产生数百行。参见p1和p2示例(仅显示3行和两个起点)

我想要的是在查询期间在cypher中相交路径,这样以后就不必这样做了。在php中,我将使用以下方法进行迭代:

$result = array_intersect($p1,$p2);
这将从上面的示例返回9,3,因为它们是所有路径共享的唯一公共节点。有没有办法在Cypher中执行此操作,这样我就不会返回数百行


谢谢

我相信这将满足您的需要

下面是正在考虑的数据的图片。

编辑:更新解决方案以包括第三条路径

// match the two different paths with the common ending i
match p1=(n1:Node {name: 1 })-[:SUB*]->(i)
, p2=(n2:Node {name: 6 })-[:SUB*]->(i)
, p3=(n3:Node {name: 4 })-[:SUB*]->(i)

// collect both sets of paths for every 
with i, collect(p1) as p1, collect(p2) as p2, collect(p3) as p3

// recombine the nodes of the first path(s) as distinct collections of nodes
unwind p1 as p
unwind nodes(p) as n
with i, p2, p3, collect( distinct n ) as p1

// recombine the nodes of the second path(s) as distinct collections of     
unwind p2 as p
unwind nodes(p) as n
with i, p1, p3, collect( distinct n ) as p2

// recombine the nodes of the third path(s) as distinct collections of     
unwind p3 as p
unwind nodes(p) as n
with i, p1, p2, collect( distinct n ) as p3

// return the common ending node with the nodes common to each path
return i, [n in p1 where n in p2 and n in p3 | n.name] as n

谢谢,这似乎有效。我无法更改返回线路以接受两条以上的路径,例如p3 p4等。。我如何组合两个以上?谢谢我添加了一个3路径解决方案。如果我有时间的话,我会看看是否可以为你推出一个通用的n路径解决方案。非常感谢这个Dave-你让它看起来很简单!
// match the two different paths with the common ending i
match p1=(n1:Node {name: 1 })-[:SUB*]->(i)
, p2=(n2:Node {name: 6 })-[:SUB*]->(i)

// collect both sets of paths for every 
with i, collect(p1) as p1, collect(p2) as p2

// recombine the nodes of the first path(s) as distinct collections of nodes
unwind p1 as p
unwind nodes(p) as n
with i, p2, collect( distinct n ) as p1

// recombine the nodes of the second path(s) as distinct collections of     
unwind p2 as p
unwind nodes(p) as n
with i, p1, collect( distinct n ) as p2

// return the common ending node with the nodes common to each path
return i, [n in p1 where n in p2 | n.name] as n
// match the two different paths with the common ending i
match p1=(n1:Node {name: 1 })-[:SUB*]->(i)
, p2=(n2:Node {name: 6 })-[:SUB*]->(i)
, p3=(n3:Node {name: 4 })-[:SUB*]->(i)

// collect both sets of paths for every 
with i, collect(p1) as p1, collect(p2) as p2, collect(p3) as p3

// recombine the nodes of the first path(s) as distinct collections of nodes
unwind p1 as p
unwind nodes(p) as n
with i, p2, p3, collect( distinct n ) as p1

// recombine the nodes of the second path(s) as distinct collections of     
unwind p2 as p
unwind nodes(p) as n
with i, p1, p3, collect( distinct n ) as p2

// recombine the nodes of the third path(s) as distinct collections of     
unwind p3 as p
unwind nodes(p) as n
with i, p1, p2, collect( distinct n ) as p3

// return the common ending node with the nodes common to each path
return i, [n in p1 where n in p2 and n in p3 | n.name] as n