Re: [RavenDB] Next & Previous Documents

80 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
May 23, 2013, 2:31:18 AM5/23/13
to ravendb
What would you define as the prev/next?


On Wed, May 22, 2013 at 9:50 PM, Neil Kinnish <te...@mixture.io> wrote:
Hi,

I was wondering if there was a nice and efficient way in Raven to get the next and previous documents based on the document being loaded.

session.Load<Class>("items/1")

Thanks

Neil

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mauro Servienti

unread,
May 23, 2013, 2:56:02 AM5/23/13
to rav...@googlegroups.com

A responder in a bundle that allows you to write something like:

 

session.Load<MyDoc>( “-id-” ).Next();

 

the problem, as Oren stated, is that the definition of next/previous is something that is known to you not to RavenDB.

 

.m

Neil Kinnish

unread,
May 23, 2013, 4:17:58 AM5/23/13
to rav...@googlegroups.com
Yes, sorry should have explained better

I will have my main document via .Load<Class>(id)

I then need to query all objects and grab the items either side of my main document.

I can do this in Linq using skipwhile and takewhile, but this is not possible in ravendb as far as I am aware.

And of course I can manually run a query using logic that ignores the document I have for both next and previous (similar to how they do this in RacoonBlog) - but this will lead to 3 queries and I suppose I was wondering if there is a more efficient way to achieve this.

Thanks

Neil

Oren Eini (Ayende Rahien)

unread,
May 23, 2013, 4:20:31 AM5/23/13
to ravendb
What _is_ either side?


--

Kijana Woodard

unread,
May 23, 2013, 9:17:20 AM5/23/13
to rav...@googlegroups.com

I think you mean like if you load a blog post, the next and previous by date. One solution is to do the three queries using Lazily. Another would be to store next/prev ids in the blog itself, but that would require thought if you want to be able to move posts around in time.

Neil Kinnish

unread,
May 23, 2013, 6:21:14 PM5/23/13
to rav...@googlegroups.com
Kijana is correct.

I have resolved this and am simply loading the next and previous documents manually using a lucene query, using the date and ignoring the item that I have already.

I have hit a strange issue here though - for some reason:

.WhereGreaterThanOrEqual

and

.WhereLessThanOrEqual

on a date does not seem to be working as expected.

If I do the same with a linq query eg: Where(c => c.date => mydate) this works correctly, but I need to use a Lucene query for this.

Here's what the real query looks like: 

ProjectId:projects/3617 AND Prefix:portfolio AND Date:[2013-05-23T11:48:57.0648450 TO NULL] AND -__document_id:posts/3617/portfolio/graffiti

However this seems to ignore the date range and just bring back everything.

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 1:40:02 AM5/24/13
to ravendb
Hm, something with ms?
Can you create a failing test?


--

Neil Kinnish

unread,
May 24, 2013, 4:42:51 AM5/24/13
to rav...@googlegroups.com
It does seem to be an issue with Milliseconds (posts are same date + time - milliseconds differ).

As mentioned this is not an issue for a standard Linq query, but with lucene, Milliseconds seem to be ignored for both the less & greater than, but also ordering.

I realise storing all of this precise information is probably overhead, but is there a way around this?

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 4:44:18 AM5/24/13
to ravendb
Can you create a failing test?

Neil Kinnish

unread,
May 24, 2013, 5:14:24 AM5/24/13
to rav...@googlegroups.com
I can create and post tests yes, but I have just realised my mistake, I had...

Index(x => x.Date, FieldIndexing.Analyzed);

Sorry for bothering you on this.

Chris Marisic

unread,
May 24, 2013, 9:23:21 AM5/24/13
to rav...@googlegroups.com
yeah analzyed dates would be wierd.
Reply all
Reply to author
Forward
0 new messages