0

I have following situation:

User (userId,Name)
Group (groupId,groupName,createdTime)

User ------ created -------> Group1
User ------ created -------> Group2
User ------ created -------> Group3

I want to get the list of group created by user in desending order. I have this query

//g is TitanGraph
g.query().interval("createdTime",0,time).orderBy("createdTime", 
                 Order.DESC).limit(5).vertices();

This will traverse whole graph. but i want for the specific user using userId

Means i will take userId and show all group created by that userId sorted by createdTime

One I was trying

g.query().has(`userId`,'xyz').interval("createdTime",0,time).orderBy("createdTime", 
                 Order.DESC).limit(5).vertices();

Din't work.it was just returning nothing.

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147

2 Answers2

1

What about this?

g.v(userId).outE.interval("createdTime",0,time).orderBy("createdTime", Order.DESC).limit(5);
MarcoL
  • 9,829
  • 3
  • 37
  • 50
1

You are using a Graph Query when you want a Vertex Query:

https://github.com/thinkaurelius/titan/wiki/Vertex-Centric-Indices

Query the vertex first and then execute the query from there, like:

Vertex v = g.getVertex(userId)
v.query().has(`userId`,'xyz').interval("createdTime",0,time).orderBy("createdTime", 
                 Order.DESC).limit(5).vertices()

I guess this is basically the answer from @MarcoCI written with Titan/Java instead of Gremlin.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • I knew this but the thing is `VertexQuery` doensn't have `OrderBy` method.Its `TitanGraphQuery` that has method `OrderBy`. and you can get `TitanGraphQuery` from `TitanGraph` only. `IdGraph` doesn't have any OrderBy support. Here I am talking about `IdGraph` cos `g.getVeretx(userId)` will only run in `IdGraph` cos `userId` is custom id given to vertex by me and `TitanGraph` doen't support that. So basically the thing is I will have to use IdGraph to get a particular vertex by its Id and so I wont get OrderBy query method.Right? – Manish Kumar Feb 13 '14 at 04:18
  • Got the solution for the same question here https://groups.google.com/forum/#!topic/aureliusgraphs/n0AyWioVnoY – Manish Kumar Feb 13 '14 at 05:31