Recursively query simpler tree-like structures with Gremlin

前端 未结 1 1084
孤街浪徒
孤街浪徒 2021-01-24 15:59

Consider the following data:

g.addV(\'RootTopic\').property(\'name\', \'A\').as(\'A\')
.addV(\'RootTopic\').property(\'name\', \'M\').as(\'M\')
.addV(\'Topic\').         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 16:03

    The by() modulator can take more than just a property key value as an argument. You can also pass in an anonymous traversal which would thus allow:

    g.V().hasLabel('RootTopic').
      repeat(out()).times(2).
        emit().
      tree()
        by(values('name','k1','k2').fold())
    

    or you might use project() if you had more complex output:

    g.V().hasLabel('RootTopic').
      repeat(out()).times(2).
        emit().
      tree()
        by(project('name','k1','degree').
             by('name').
             by('k1').
             by(both().count())
    

    The main point to take away here is that with an anonymous traversal you can develop just about any output you would like.

    0 讨论(0)
提交回复
热议问题