Optimize Neo4j Cypher query

前端 未结 2 1568
走了就别回头了
走了就别回头了 2021-01-23 21:21

What I\'m doing is to get all profiles* who has a specific directed relation to a users profile* and if those have an alternate profile* get those in

2条回答
  •  礼貌的吻别
    2021-01-23 21:46

    This is how I solved it:

    START User=node({source}) 
    MATCH User-[:profile]->ProfileA-[rel:related]->ProfileB<-[?:me]->ProfileB2-[relB?:related]-ProfileA2
    WHERE relB IS NULL OR User-[:profile]->ProfileA2
    RETURN ProfileB, COLLECT(ProfileB2), rel, relB
    LIMIT 25
    

    The ProfileA2<-[:profile]-User seemed to produce an endless loop.

    Recommendations are still welcome.

提交回复
热议问题