문제

I need to find connections between all the nodes (with a "Hashtag" label) connected to the main user node.

So far, I came up with a solution like this, but it seems to me a bit inefficient, because I traverse the graph twice to first find c1 and then c2.

Anybody has better ideas?

MATCH (u:User{uid:"777"}), (c1:Hashtag), (c2:Hashtag), 
c1-[:BY]->u, c2-[:BY]->u, c1-[rel:TO]->c2 RETURN rel,c1,c2;

(I'm working with Neo4J / Cypher 2.0)

도움이 되었습니까?

해결책

Try this, play around with it and let me know the output.

MATCH (u:User {uid:"777"})
WITH u
MATCH u<-[:BY]-(c1:Hashtag)-[rel:TO]-(c2:Hashtag)--(u)
RETURN rel, c1, c2

Basically, the idea here is as follow:

  1. Match the User node first
  2. Use it to match all 'Hashtag' nodes
  3. Use it to match to all 'Hashtag' nodes connected to the previous 'Hashtag nodes
  4. Return the 'rel', which is all the relationships from 'Hashtag' nodes to 'Hashtag' nodes which are connected to the user 777
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top