cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to match a given node's all related user?

coolyrat
Node Clone

Hi,
I am given a Core User and need to match all the relationships start with Core User to other Users. Core User is also labeled with User. I have the following relationships:

  • (cu:User)-[:FOLLOWING]->(:User), Core User is following some Users
  • (cu:User)<-[:FOLLOWING]-(:User), some Users are following Core User
  • (cu:User)-[:POSTED]->(:Post)<-[:COMMENTED]-(:User), some Users that commented Core User's Post
  • (cu:User)-[:FAVOURITE]->(:Post)<-[:COMMENTED]-(:User), some Users that commented Core User's favourite Post
  • (cu:User)-[:OWNED]->(:Chat)<-[:INVOLVED]<-(:Post)<-[:POSTED]-(:User), some Users that posted involved Core User's owned chat
  • (cu:User)-[:OWNED]->(:Chat)<-[:INVOLVED]<-(:Post)<-[:COMMENTED]-(:User), some Users that commented a Post which involved in Core User's owned chat

I start with something like below, but it does't seem right.

Match (u:User)
Where u.id = '1234'
Match (u)-[*1..3]-(t:User)
RETURN count(t)
1 REPLY 1

Since there are many paths from the Core user to other nodes t will have duplicates.

If you are only interested in the nodes that are 1 to 3 hops away from the Core user, you could return DISTINCT t.

Elaine