如果出于一些原因,您需要索引包含在查询结果中,您可以像下面这样使用Groovy的withIndex或者indexed方法。
If for any reason you wanted an index value included as part of the results from a query you can
use the Groovy withIndex or indexed methods as shown below.
这些内容将在下一节中讲到,小精灵原生index步骤是在阿帕奇Tinkerpop3.4版本中开始引入的。
As covered in the next section, a native Gremlin index step was introduced in the
Apache TinkerPop 3.4 release.
withIndex是把索引加在了列表的最后,而indexed方法是把索引加在了开始。您可以提供一个参数做为索引的开始值。如果没有提供开始值,默认的索引开始值就是0.
The withIndex method adds the index value at the end of a list whereas the indexed method adds it
at the start. You can provide a starting index value as a parameter. If no value is provided the
default value for the first index will be zero.
注意indexed,withIndex是Groovy语句的方法,而不是小精灵遍历语言中的步骤。它们只能用在允许使用Groovy代码做为查询语句的一部分的图数据库中。
Note that indexed and withIndex are Groovy methods and not Gremlin traversal
steps. They will only work using graph databases that allow Groovy code to be
included as part of a query.
这是同一个查询但是索引的开始是数字1.
Here is the same query as before but using 1 as the starting index.
这个查询又用了一次,但是这次用indexed方法来生成索引的值。
Below is the query used again but this time with the indexed method being used to generate the
index value.
浙公网安备 33010602011771号