This is how you can sort (order) results from Neo4j graph using Gremlin:
g.v(id).out('knows').sort{it.name}
or
g.v(id).out('knows').sort{a,b -> a.name <=> b.name}
This is how to limit result using offset/skip and limit:
g.v(id).out('knows')[0..9]
However if you combine both sort and limit
g.v(id).out('knows').sort{it.name}[0..9]
it would throw an error...
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList$ListItr.getAt() is applicable for argument types: (groovy.lang.IntRange) values: [0..9]
Possible solutions: getAt(java.lang.String), getAt(int), next(), mean(), set(java.lang.Object), putAt(java.lang.String, java.lang.Object)
It took me a while to figure out that native Groovy methods like sort do not return Pipes, but iterators, iterables, etc. As such, to convert one of these objects back into a Pipeline flow you need to use _():
g.v(id).out('knows').sort{it.name}._()[0..9]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With