Paging with NestedProperties and SkippedResults

34 views
Skip to first unread message

spokeypokey

unread,
Dec 16, 2011, 5:41:03 PM12/16/11
to rav...@googlegroups.com
A couple of questions about paging through query results sets
when using documents with nested array structures:

1. I realize that when you query indexes constructed in the
following way, paging is straight-forward; you can use Skip().Take(),
since there are no SkippedResults:


public class NestedPropertyIndex1 : AbstractIndexCreationTask<Provider>
{
    public NestedPropertyIndex1()
    {
        Map = providers =>
              from p in providers
              select new
              {
                  p.Name,
                  p.Zip,
                  Categories_Name = p.Categories.Select(c => c.Name),
                  Categories_EffectiveFrom = p.Categories.Select(c => c.EffectiveFrom),
                  Categories_EffectiveThrough = p.Categories.Select(c => c.EffectiveThrough),
              };
    }
}


However, this indexing tactic isn't always appropriate. Sometimes it's necessary to create
an index in the following fashion due to querying requirements:

public class NestedPropertyIndex2 : AbstractIndexCreationTask<Provider>
{
    public NestedPropertyIndex2()
    {
        Map = providers =>
              from p in providers
              from c in p.Categories
              select new
              {
                  p.Name,
                  p.Zip,
                  Categories_Name = c.Name,
                  Categories_EffectiveFrom = c.EffectiveFrom,
                  Categories_EffectiveThrough = c.EffectiveThrough,
              };
    }
}

For example, given the following query:

var result = (from p in session.Query<Provider, NestedPropertyIndex2>()
              where p.Categories.Any(c => c.Name == "Category1" && c.EffectiveFrom < new DateTime(2011, 1, 2))
              select p).ToArray();
             
it's necessary to use NestedPropertyIndex2 due to the fact that BOTH the Category Name
AND EffectiveFrom date from from a single child object need to match the query constraints.
It isn't valid to match the Category Name from one child object and the Category EffectiveDate
from a different child object, which can happen if you use NestedPropertyIndex1.

Which leads my to my real question:

When you query using NestedPropertyIndex2, you invariably get "SkippedResults".
After having reviewed Ayende's "IndexQueryOperation" code, it seems to me that
the only paging navigation I can reliably do (without using estimation logic and
trial and error searches) is:
  - Get the first page of results
  - Get the next page of results.
 
 There doesn't seem to be any reliable way of doing either of the following:
   - Get any previous page of results (assuming the previous page is not the first page)
   - Get any succeeding page that is not the next page.
  
 What I am looking for is confirmation as to whether I need to abandon true, simple paging
 when using an index like NestedPropertyIndex2.

Oren Eini (Ayende Rahien)

unread,
Dec 18, 2011, 5:36:02 AM12/18/11
to rav...@googlegroups.com
When you have a situation where you have SkippedResults > 0, yes, you can only page to the next post, you can't just page to an arbitrary location.
In practice, those sort of situations are relatively rare (needing to do an exact page find with SR > 0)

Stan A

unread,
Apr 17, 2013, 1:13:28 PM4/17/13
to rav...@googlegroups.com
Has there been any update to this in any recent builds?  Or is there a workaround?

I don't agree that this situation is relatively rare as why does most pagination navigation (e.g. Google Search) on the internet include the ability to skip to a particular page rather than just having next and previous buttons. Even if it is rare, I (and my users) still need to do it sometimes.

Is there a way to get a standard Skip/Take behavior that just takes into account of skipped results?  Or is there another workaround that I could implement?

The only workaround I can think of at the moment is to query all the results on the previous pages and see how many were skipped and used that to get the current page.  But what's the point of the pagination if I have to do that?

Any help would be appreciated!

Kind Regards,

David

Oren Eini (Ayende Rahien)

unread,
Apr 17, 2013, 2:20:11 PM4/17/13
to ravendb
This is 2 years old. Please do not open old threads.

At any rate, the behavior has changed in 2.0, and we track this for you.



--
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.
 
 

Reply all
Reply to author
Forward
0 new messages