【问题标题】:NEO4J find any nodes that have relationships (direct/indirect) with all nodes in a setNEO4J 查找与集合中的所有节点有关系(直接/间接)的任何节点
【发布时间】:2021-12-14 08:36:49
【问题描述】:

我是 neo4j 的新手,所以我可能在这里犯了一些基本错误:

这是我的图表的一个子集:

我有3种节点:

  • (蓝色)属性
  • (红色)业务
  • (黄色)促销

attributes 可以与 promotions 和 businesses (:TAGS) 建立关系

这是迄今为止我最好的猜测密码查询。

MATCH(a:Attribute)--(b:Business)--(p:Promotion)
WHERE a.name IN ["business", "casual", "happy_hour"]
RETURN a, b, p
UNION
MATCH(a:Attribute)--(p:Promotion)--(b:Business)
WHERE a.name IN ["business", "casual", "happy_hour"]
RETURN a, b, p;

这不是我想要的,它返回与一个或多个 attributes

相关的promotions

我只想在给定的一组属性中返回与 all attributes 有关系的 promotions。我该怎么做?

【问题讨论】:

    标签: neo4j cypher neo4j-ogm


    【解决方案1】:

    这应该可行。

    // create collection of myTagNodes
    WITH ["business", "casual", "happy_hour"] AS myTags
    MATCH (myTagNode:TAG) WHERE myTagNode.name IN myTags
    WITH COLLECT(myTagNode) AS myTagNodes
    
    // only return promotions for which all 'myTagNodes'are in the 
    // (indirectly) connected tags, i.e. through buisnesses or directly
    MATCH (p:Promotion)
         WHERE ALL(myTagNode IN myTagNodes 
                   WHERE myTagNode IN [(p)<-[*1..2]-(pTagNode:TAG) | pTagNode] 
               )
    RETURN p
    

    另请参阅https://neo4j.com/docs/developer-manual/current/cypher/syntax/lists/#cypher-list-comprehension 和 https://neo4j.com/docs/developer-manual/current/cypher/syntax/lists/#cypher-pattern-comprehension

    【讨论】:

    • 感谢您的帮助,您能否指出一些关于此的文档:[(p)&lt;-[*1..2]-(pTagNode:TAG) | pTagNode]
    • 添加了文档链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 2016-01-25
    相关资源
    最近更新 更多