【问题标题】:Gremlin query: Another way to write this in a loopGremlin 查询:另一种在循环中编写它的方法
【发布时间】:2023-04-03 02:21:01
【问题描述】:
g.v(1).out('__SYSTEM_HAS_CHILD').filter{it.name == 'Journal'}.out('__SYSTEM_HAS_CHILD').filter{it.name == 'travel'}.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Alaskan-Natives'}.map

也许存储一个包含项目的数组,然后遍历每个执行输出并将其附加到 it.name;并迭代(计数)以确保我们不会超出数组的长度。

【问题讨论】:

    标签: graph neo4j graph-databases gremlin


    【解决方案1】:

    您可以像这样重新格式化管道:

    pipe = g.v(1)
    pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Journal'}
    pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'travel'}
    pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == 'Alaskan-Natives'}
    pipe.map
    

    然后您可以使用 Groovy 构造将其变成一个循环:

    names = ["Journal", "travel", "Alaskan-Natives"]
    pipe = g.v(1)
    names.each() { name -> 
      pipe = pipe.out('__SYSTEM_HAS_CHILD').filter{it.name == name} 
    }
    pipe.map
    

    注意:为什么要将管道作为地图返回?要迭代管道,您可以使用以下任一方法:

    pipe.iterate()
    pipe.toList()
    

    https://github.com/tinkerpop/gremlin/wiki/Gremlin-Methods

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多