简体   繁体   English

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

[英]How to retrieve only the nodes from the path in Neo4J Cypher query?

I have a query of the following kind: 我有以下类型的查询:

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;

Right now it returns a list of all the paths p in the coll variable. 现在,它返回coll变量中所有路径p的列表。 I want it to list only the nodes c . 我希望它仅列出节点c How to make this possible? 如何做到这一点?

Maybe the query is not right, in this case, what I'm trying to do is to 也许查询不正确,在这种情况下,我想做的是

1) Find all statements made by a user; 1)查找用户所作的所有陈述;

2) Find the nodes that connect those two statements; 2)找到连接这两个语句的节点;

3) Return those statements, which have the most nodes connecting them, ORDER BY DESC, including the names of the actual nodes that connect them. 3)返回那些连接最多的节点(ORDER BY DESC)的语句,包括连接它们的实际节点的名称。

Thank you! 谢谢!

I can't test it at the moment, but you could try something like 我目前无法测试,但是您可以尝试类似

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

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

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