如何使用空过滤器在一个cypher查询中返回2个集合

时间:2013-03-28 14:51:00

标签: neo4j cypher

所以我尝试从单个密码查询中返回2组:

鉴于父节点在索引中,那么

  1. 父节点的子节目
  2. 无子节点的父节点。
  3. 我能够得到一个类似的查询,它返回一组中的索引中的父项,以及另一组中的子项,如下所示

    START Parents = node:app_fulltext('name:"City"'),
     MATCH Parents-[?:ChildOf]-Apps 
     RETURN collect(Apps.Title), collect(Parents.Name);
    
    ==> +--------------------------------------------------------------+
    ==> | collect(Apps.Title) | collect(Parents.Name)                  |
    ==> +--------------------------------------------------------------+
    ==> | ["Empty City 3D"]   | ["Empty City 3D","Empty City 3D Fake"] |
    ==> +--------------------------------------------------------------+
    

    这接近我想要的。但是,我想从Parents.Name中过滤掉Apps.Title集合中已有Child的项目。

    这是我想要的结果集。 “Empty City 3D Fake”没有任何子节点,因此在Parents.Name中返回。

    ==> +--------------------------------------------------------------+
    ==> | collect(Apps.Title) | collect(Parents.Name)                  |
    ==> +--------------------------------------------------------------+
    ==> | ["Empty City 3D"]   | ["Empty City 3D Fake"]                 |
    

    当我刚刚添加了Where r is null子句时,它什么都没有返回,所以我最终必须添加两个相同的开始父集(Parents和Parents2)才能执行此操作。然而,这看起来非常狡猾,所以我希望有更好的方法。

    START Parents = node:app_fulltext('name:"City"'), 
          Parents2 = node:app_fulltext('name:"City"')
          MATCH Parents-[r?:ChildOf]-Children, Parents2-[:ChildOf]-Apps 
          Where r is null 
          return collect(Apps.Title), collect(Parents.Name);
    
    
    ==> +--------------------------------------------------------------+
    ==> | collect(Apps.Title) | collect(Parents.Name)                  |
    ==> +--------------------------------------------------------------+
    ==> | ["Empty City 3D"]   | ["Empty City 3D Fake"]                 |
    ==> +--------------------------------------------------------------+
    

1 个答案:

答案 0 :(得分:1)

你可以尝试一下 -

START Parents = node:app_fulltext('name:"City"'),
 MATCH Parents-[?:ChildOf]-Apps 
 WITH collect(Apps.Title) as myapps, collect(Parents.Name) as myparents
 RETURN myapps, filter(x in parents : not x in myapps) as myfilteredparents