Search code examples
rangelimitgremlinoffset

How to calculate range() for the graph in Gremlin pagination query?


How to calculate range() for the graph in Gremlin pagination query with input of page number and limit.


Solution

  • If the page number starts with 1, then

    start_range = (page - 1 )* limit
    end_range = start_range + limit
    
    g.V('id').outE().hasLabel('created_by').range(start_range, end_range).inV()
    

    For some reason, if the page number starts from 0, then

    start_range = page * limit
    end_range = start_range + limit
    
    g.V('id').outE().hasLabel('created_by').range(start_range, end_range).inV()