简体   繁体   English

Gremlin:如何将多个顶点选择()到一个集合中,然后获得具有最高属性值的顶点

[英]Gremlin: How to select() multiple vertices into a collection then get the one with the highest property value

Take a traversal like this: 像这样遍历:

g.V().as('a')......has(name,'test').as('b').....select('a','b')

At this point, now I've stored and selected out 'a' and 'b', I want to identify the one with the high property value (eg a.score==2 , b.score==4 , so choose 'b') 在这一点上,现在我已经存储并选择了“ a”和“ b”,我想标识具有较高属性值的a.score==2 (例如a.score==2b.score==4 ,所以选择“ b')的

How do I do it? 我该怎么做?

It's easier if you give every candidate on the path the same label: 如果为路径上的每个候选者都赋予相同的标签会更容易:

g.V().as('a')....
  has('name,'test').as('a').
  select(all, 'a').
  order(local).
    by('score', decr).
  limit(local, 1)

Here's how it looks on the modern toy graph: 这是现代玩具图上的外观:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().as('a').out('knows').as('a').select(all, 'a')
==>[v[1],v[2]]
==>[v[1],v[4]]
gremlin> g.V().as('a').out('knows').as('a').
......1>   select(all, 'a').
......2>     by(unfold().valueMap(true).fold())
==>[[label:person,name:[marko],age:[29],id:1],[label:person,name:[vadas],age:[27],id:2]]
==>[[label:person,name:[marko],age:[29],id:1],[label:person,name:[josh],age:[32],id:4]]

At this point we know that the expected result is v[1] (29 > 27) for the first path and v[4] (32 > 29) for the second path. 至此,我们知道第一条路径的预期结果为v[1] (29> 27),第二条路径的预期结果为v[4] (32> 29)。

gremlin> g.V().as('a').out('knows').as('a').
......1>   select(all, 'a').
......2>   order(local).
......3>     by('age', decr).
......4>   limit(local, 1)
==>v[1]
==>v[4]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM