简体   繁体   中英

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. I want it to list only the nodes 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;

2) Find the nodes that connect those two statements;

3) Return those statements, which have the most nodes connecting them, ORDER BY DESC, including the names of the actual nodes that connect them.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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