0

Take the scenario of SO,

  1. when we click Questions button it shows all question regardless of tag,

  2. when we click a tag it only shows question asked to that particular tag.

Second is ok, I will just go to that particular Tag vertex and fetch the sorted data based on attached edge.

How will i implement the first scenario in sorted order.? I will have java question, html question, c++ question vertex... so and so. How will I fetch all these in sorted order? What will be the query?

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

1 Answers1

0

Obviously, you are trying to avoid iterating/sorting all vertices to find recent questions. One way might be to build some sort of date structure into your schema like:

year --> month --> day --> question

If you have a sufficient number of "questions" in your you use case you might consider breaking time down further to hours, minutes, etc (or a higher level of aggregation....maybe you just need year and month). Index the edges between the year, month, day, and question using a reverse sort order of the time, so that you can just do:

g.V('year','2014').out.out.out[0..<10]

which would return the first 10 most recent questions. Note that Gremlin nicely compiles this to a vertex query to take advantage of your index:

gremlin> g.V.has('year','2014').out.out.out[0..<10].toString()
==>[GremlinStartPipe, GraphQueryPipe(has,vertex), IdentityPipe, VertexQueryPipe(out,[],vertex), VertexQueryPipe(out,[],vertex), VertexQueryPipe(out,[],range:[0,9],vertex), IdentityPipe]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • I think the question is, how to structure tags and questions without tagging vertices. What's the point of using an extra structure for dates and not only UNIX timestamps? – Martin Seeler Mar 15 '14 at 12:57
  • I interpreted the question as one being how to retrieve the most recent question vertices in the graph (with the mention of "tags" being incidental to the post). Perhaps I misinterpreted...I'll let @Manish clarify as to whether or not I've understood. I'm not sure I follow your question though on "extra structure for dates and not only UNIX timestamps". Do you just mean, why not just rely on a timestamp property on the question vertex to find most recent questions? If you can elaborate for me, I can try to answer. – stephen mallette Mar 15 '14 at 13:38
  • what i understood is to make `year` `month` `day` vertex then connect `question` vertex to `day`. index all these `day --> question` edge in sorted order. and then traverse from `year` to `month` to `day` to get the result.right? – Manish Kumar Mar 15 '14 at 15:22
  • yes, @Manish that's what I was suggesting as a way to get around your problem. The downside is the added "date" structure, but it seems you need a way to start your traversal that then allows use of vertex centric indices. Perhaps that will inspire you to a solution. – stephen mallette Mar 15 '14 at 17:29