1
votes

I'm trying to write a Gremlin query to traverse a graph using Tinkerpop Frames.

Here is the code I have:

@GremlinGroovy("it"
            + ".outE"
            + ".filter{it.label=='usedwith'}"
            + ".sort{-it.weight}"
            + ".toList()"
            + ".reverse()"
            + "[start, 'start+size']"
            +"._"
            + ".inV")
public Iterable<Ingredient> getMostUsedWith(@GremlinParam("start") int start, 
                                            @GremlinParam("size") int size);

I basically want to get all edges from my current vertex with type 'usedwith', sort them based on weight attribute descendingly and then get a page from the list of vertices that these edges are pointing at.

Sadly this code doesn't work and throws a lot of errors. Can you revise this?

1
1) Why do you revese the list instead of sort it ascending? 2) What is the purpose of [start, 'start+size']? A slice of the list from start to (start + size) or a list of length 2 with elements at start and (start + size)? This part is not included in your description (How do you prevent OutOfBoundExceptions?).Faber
I think Frames handles the out of bound. It works ok here. You got all of what I intended to do right in your answer. Thanks for your help.Mohamed Taher Alrefaie

1 Answers

1
votes

Maybe you could write your query as:

it.outE('usedwith').order{it.b.weight <=> it.a.weight}.inV[start..(start + size)]