Question

I am using Titan Graph Database. Say if i have a vertex V with id VID and there 10K vertices attached to it v1 with id v1id, v2 with id v2id...................v10000 with id v10000id.

Now i want pagination in getting neighbour vertices i.e 10 vertex detail per call.

It should support next and previous result. I saw limit() but it just limit the number of returned result. I saw THIS SO and seems close to what i need, but is there some range kind of thing in Titan where i can pass the start vertex id and the number of result i want??

Was it helpful?

Solution

With Gremlin you can pass indices for ranges:

  // for the second ten links
  g.v(1).outE.has('time',T.gte, fiveDaysAgoInMs)[10..19]

  // for the previous ten links
  g.v(1).outE.has('time',T.gte, fiveDaysAgoInMs)[0..9]

  // for the next ten links
  g.v(1).outE.has('time',T.gte, fiveDaysAgoInMs)[20..29]

  // for one link only
  g.v(1).outE.has('time',T.gte, fiveDaysAgoInMs)[0..<1]

Source: GremlinDocs

In Java code:

Graph g = ... // a reference to a Blueprints graph
GremlinePipeline pipe = new GremlinPipeline();

Long DAY_IN_MS = 1000 * 60 * 60 * 24;

// first 10
pipe.start(g.getVertex(1)).outE().has("time", Tokens.gte, new Date(date.getTime() - (5 * DAY_IN_MS))).range(0, 10));

// if you want next 10
pipe.next(10);

Source: GremlinPipeline, Using Gremlin though Java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top