neo4jgremlintinkerpop-frames

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


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.


Solution

  • 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);