reI’m stuck with a gremlin query to assign rank values to nodes based on a sorted list of keys passed to the query as a parameter.
Each node identified by “uniqueId” values should be assigned a rank based on order of occurrence in the reranked array.
This works:
reranked = [uniqueId1, uniqueId2, uniqueId3]
v.outE.as('e').inV.filter{it.key == reranked[2]}.back('e').sideEffect{it.rank = 2}
But this doesn’t (replacing int with for-loop variable):
reranked = [uniqueId1, uniqueId2, uniqueId3]
for (i in 1..reranked.size())
v.outE.as('e').inV.filter{it.key == reranked[i]}.back('e').sideEffect{it.rank = i}
Do you know why this doesn’t work? I’d also be happy for simpler ideas to reach the same goal.
You could do this using Groovy’s
eachWithIndexlike:I have used Gremlin’s
hasstep above because it’s much more efficient thanfilterin case of simple property look-up.