Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
neo4j独立出度联轴节_Neo4j - Fatal编程技术网

neo4j独立出度联轴节

neo4j独立出度联轴节,neo4j,Neo4j,我想计算Indegree和Outdegree,并返回一个在前5个Indegree节点和前5个Outdegree节点之间有连接的图。我已经写了一个代码作为 match (a:Port1)<-[r]-() return a.id as NodeIn, count(r) as Indegree order by Indegree DESC LIMIT 5 union match (n:Port1)-[r]->() return n.id as NodeOut, count(r) as Ou

我想计算Indegree和Outdegree,并返回一个在前5个Indegree节点和前5个Outdegree节点之间有连接的图。我已经写了一个代码作为

match (a:Port1)<-[r]-()
return a.id as NodeIn, count(r) as Indegree
order by Indegree DESC LIMIT 5
union
match (n:Port1)-[r]->()
return n.id as NodeOut, count(r) as Outdegree
order by Outdegree DESC LIMIT 5
union
match p=(u:Port1)-[:LinkTo*1..]->(t:Port1)
where u.id in NodeIn and t.id in NodeOut 
return p
匹配(a:Port1)()
返回n.id作为NodeOut,计数(r)作为Outdegree
按超出度描述限制5订购
联盟
匹配p=(u:Port1)-[:LinkTo*1..]>(t:Port1)
其中u.id在NodeIn中,t.id在NodeOut中
返回p
我得到一个错误

联合中的所有子查询必须具有相同的列名(第4行第1列(偏移量:99))“联合”


我需要对代码做哪些更改?

我们可以改进一些地方

你所做的匹配并不是获取关系的传入和传出学位的最有效方式

此外,UNION只能用于组合具有相同列的查询结果。在这种情况下,我们甚至不需要UNION,我们可以使用WITH将结果从查询的一部分传递到另一部分,并收集()中间所需的节点

请尝试以下查询:

match (a:Port1)
with a, size((a)<--()) as Indegree
order by Indegree DESC LIMIT 5

with collect(a) as NodesIn
match (a:Port1)
with NodesIn, a, size((a)-->()) as Outdegree
order by Outdegree DESC LIMIT 5

with NodesIn, collect(a) as NodesOut
unwind NodesIn as NodeIn
unwind NodesOut as NodeOut
// we now have a cartesian product between both lists
match p=(NodeIn)-[:LinkTo*1..]->(NodeOut)
return p

此外,请确保所需的方向正确,因为您正在匹配具有最高程度的节点,并获得指向具有最高程度的节点的传出路径,这对我来说可能是倒退,但您最了解您的需求。

感谢您的回复。这对我帮助很大!。但是,我没有听到你的一句话,“看起来很落后”。你这是什么意思?你的意思是说需求不是分析的一部分,或者没有价值?不,这种想法只是基于有时很容易混淆方向,以及从高向外度的节点到高向内度的节点似乎是“与当前一致”,而反向(如在你的查询中)是如何与之相反。在你完全没有背景知识的情况下,你可能会错误地混淆了方向。但如果方向如你所愿,那么一切都很好。
...
match p = shortestPath((NodeIn)-[:LinkTo*1..]->(NodeOut))
return p