从Neo4j cypher查询返回边缘列表

时间:2017-04-13 14:50:49

标签: r neo4j cypher igraph

您好我最近开始使用Neo并且想知道如何查询图表以返回显示连接的两列ID。

MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE  s1.StartDate> '2015-01-01' 
RETURN s1.StudentID, s2.StudentId

上面给出了s1的所有连接但是它没有显示任何其他连接。如何将此图表中的所有连接收集到一个边缘列表中?计划是在RNeo4j中使用此查询并使用igraph进行分析。

提前致谢

2 个答案:

答案 0 :(得分:1)

如果您只是对每条路径中的节点对感兴趣,那么您可以执行以下操作。

此查询获取匹配的路径,对每个路径中的节点对进行分组,然后仅返回不同的对。

MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE  s1.StartDate> '2015-01-01'
WITH REDUCE(pairs =[],r in relationships(path) | pairs + [[startNode(r).StudentId,endNode(r).StudentId]]) as pairs
UNWIND pairs as pair
WITH DISTINCT pair
RETURN pair[0] as from, pair[1] as to

答案 1 :(得分:0)

最简单的方法是返回路径

MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE  s1.StartDate> '2015-01-01' 
RETURN path

因为你可能对返回感兴趣:FRIENDS关系,因为它们都是一样的,你只能返回路径的节点

MATCH path=(s1:Student{StudentId: 7079945})-[r:FRIENDS*6..9]->(s2:Student)
WHERE  s1.StartDate> '2015-01-01' 
RETURN nodes(path)

您可以在documentation找到更多路径功能。