0

I have a neo4j graph which looks like this :

  (user)-LIKES->(Actor)
    |              ^
    |              |
  FRIENDS         LIKES
    |              |
    v              |
  (user2)-----------

Which states, user friends with user2 and user likes actor and friend (user2) likes actor too.

Now, given actor, when I try to pull all the users friends who like Actor, I do something like this :

START user=node(*)
MATCH (user)-[:FRIENDS]-(friend)-[like_rela:LIKES]-(actor)
WHERE user.uid=123 AND actor.id = 234
RETURN DISTINCT friend, like_rela;

The above query returns all my user's friends who like an actor. This does not return the relationship between the user and the actor though. Is there a way I can club this into the same query ?

I am using Neo4j 1.9

Thanks

1 Answer 1

0

This might be close to what you are after:

MATCH (user {id:123})-[:FRIENDS]-(friend)-[f_like_rel:LIKES]->(actor {id:234})
OPTIONAL MATCH (user)-[u_rel]-(actor)
RETURN DISTINCT friend, u_rel, f_like_rel;

Notes:

  1. The above (user {id:123})-[:FRIENDS]-(friend) pattern is non-directional, so that the FRIENDS relationship can go either way.
  2. However, the (friend)-[f_like_rel:LIKES]->(actor {id:234}) pattern is directional, as I presume you don't want to capture any actors who happen to like your friend (without the feeling being reciprocated).
  3. u_rel can be of type FRIENDS or LIKES; or it can be NULL if the user has no relationship with the actor. I left this pattern non-directional, but you may want to make it directional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.