Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-29-2018 05:59 AM
My node structure is like this -
User -> FOLLOWS -> User
User -> FOLLOWS_TEAM -> Team
By using following code I can get Messages POSTED by User and Team I am following.
MATCH (me:User)-[u_rel_source:FOLLOWS_TEAM|:FOLLOWS*0..1]->(users)-[u_rel:POSTED]->(msg:Message)
Question -
Now I want to add one more node :Organisation above Team like
Team<-[r:HAS]-Oraganisation
and User can follow Organisation, in that case User should get messages posted by Teams of followed Organisation.
How can I do it in one query and how relationships will be?
I am not able to find logic for same.
Thanks in advance
12-30-2018 03:02 PM
What data do you want to return? Just the messages, or do you need the relationships returned too? Are you interested only in the graph result view or do you have a specific tabular output as a requirement?
01-02-2019 03:17 AM
I want to return relationships and messages both in graph result view.
01-02-2019 04:19 AM
Give this a try:
MATCH (me:User)-[:FOLLOWS_TEAM|:FOLLOWS*0..1]->(userOrTeamOrOrg)-[:HAS*0..1]->(userOrTeam)-[:POSTED]->(msg:Message)
This way, if the thing being followed is an :Organization, then there's a :HAS relationship to traverse to get to the :Team. Otherwise, if the node is a :Team or :User there will be no outgoing :HAS relationship.
EDIT
Fixed direction of :HAS relationship.
01-02-2019 05:21 AM
I tried same,
Its not working.
Here its not checking if me following org.
01-02-2019 05:40 AM
Ah, you didn't mention you were using a separate relationship type for that. Add that in, see if it works.
01-02-2019 06:16 AM
yes I tried that as well.
Like this -
MATCH (me:User)-[post_rel_source:FOLLOWS_TEAM|:FOLLOWS*0..1]->(u)<-[:EVENTS_OF_ORG*0..1]-(users)<-[f:EVENTS_OF_ORG]-(me)
its not showing result of followed teams and users also.
01-02-2019 01:38 PM
Again, you never mentioned this relationship. Can you provide the relationships in use around the :Organization node and how they're used?
I had assumed you use something like
(:User)-[:FOLLOWS_ORG]->(:Organization)
(:Team)<-[:HAS]-(:Organization)
Which would mean we have to traverse the following paths:
(:User)-[:FOLLOWS_ORG]->(:Organization)-[:HAS]->(:Team)-[:POSTED]->(:Message)
(:User)-[:FOLLOWS_TEAM]->(:Team)-[:POSTED]->(:Message)
(:User)-[:FOLLOWS]->(:User)-[:POSTED]->(:Message)
So the patterns to traverse would be as previously posted (with a quick fix to the direction of :HAS):
MATCH (me:User)-[:FOLLOWS_TEAM|FOLLOWS_ORG|FOLLOWS*0..1]->(userOrTeamOrOrg)-[:HAS*0..1]->(userOrTeam)-[:POSTED]->(msg:Message)
All the sessions of the conference are now available online