如何从Neo4J Cypher查询中的路径中仅检索节点?

时间:2014-03-22 21:07:51

标签: neo4j cypher

我有以下类型的查询:

MATCH (u1:User{name:"user_name"}), (s1:Statement), s1-[:BY]->u1 
WITH DISTINCT s1,u1 
MATCH (s2:Statement), s2-[:BY]->u1, 
p=s1<-[:OF]-c-[:OF]->s2 
WHERE s1 <> s2 
WITH collect(p) AS coll, count(p) AS paths, s1, s2 
RETURN s1,s2,paths,coll 
ORDER BY paths DESC 
LIMIT 2;

现在它返回coll变量中所有路径p的列表。我希望它只列出节点c。如何做到这一点?

也许查询不对,在这种情况下,我要做的是

1)查找用户发表的所有陈述;

2)找到连接这两个语句的节点;

3)返回那些连接它们的节点最多的语句ORDER BY DESC,包括连接它们的实际节点的名称。

谢谢!

1 个答案:

答案 0 :(得分:1)

我目前无法测试,但您可以尝试类似

的内容
MATCH (u:User {name:"user_name"})<-[:BY]-(s1)<-[:OF]-(c)-[:OF]->(s2)-[:BY]->(u)
RETURN s1, s2, collect(c) as connections 
ORDER BY length(connections) DESC 
LIMIT 2