How to parameterize the sort filter using tinkerpop gremlin / frames?

80 views Asked by At

I want to sort my results using a given fieldname:

@GremlinGroovy(value = "it.in('HAS_USER').sort{fieldName}._()[skip..limit]")
public Iterable<TPUser> getUsersInOrder(@GremlinParam("fieldName") String fieldName, @GremlinParam("skip") int skip, @GremlinParam("limit") int limit);

Unfortunately the results for getUsersInOrder("it.username", 0, 5) are not sorted as expected. When i replace fieldName in the gremlin code with "it.username" the results are ordered by the username.

1

There are 1 answers

1
Jotschi On BEST ANSWER

It looks like the sort method is part of groovy and not gremlin. Instead the order method can be used to sort entries:

@GremlinGroovy(value = "it.in('HAS_USER').order({ it.b.getProperty(fieldName) <=> it.a.getProperty(fieldName) })[skip..limit]")
public Iterable<TPUser> getUsersInOrder(@GremlinParam("fieldName") String fieldName, @GremlinParam("skip") int skip, @GremlinParam("limit") int limit);