简体   繁体   English

从 Neo4j 密码查询返回边缘列表

[英]Returning edge list from Neo4j cypher query

Hi I have recently started using Neo and wanted to know how I can query a graph to return two columns of IDs showing connections.嗨,我最近开始使用 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

The above gives me all the connection for s1 however It doesn't show any other connections.以上为我提供了 s1 的所有连接,但是它没有显示任何其他连接。 How can I collect all of the connections in this graph into one edge list?如何将图中的所有连接收集到一个边列表中? The plan is to use this query in RNeo4j and analyse with igraph.计划是在 RNeo4j 中使用此查询并使用 igraph 进行分析。

Thanks in advance提前致谢

If you are literally just interested in the pairs of nodes in each path then you could do something like the following.如果您实际上只是对每条路径中的节点对感兴趣,那么您可以执行以下操作。

This query takes the matched paths, groups the pairs of nodes in each path and then only returns the distinct pairs.此查询采用匹配的路径,将每个路径中的节点对分组,然后仅返回不同的对。

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

The easiest way to do this is to return the path最简单的方法是返回路径

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

As you are probably not interested in returning :FRIENDS relationship, because they are all the same you can return only nodes of the path由于您可能对返回 :FRIENDS 关系不感兴趣,因为它们都是相同的,因此您只能返回路径的节点

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

You can find more functions for path in documentation .您可以在文档中找到路径的更多功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM