RavenDB Paging Index

I have a linq query like

var mdls = (from mdl in query dbSession.Query<MyModel>("MyIndex") orderby mdl.Name select dept).Skip(page.Value).Take(4); 

Where "MyIndex" is a simple index defined in RavenDB. I know that when querying an index in RavenDB, it returns "TotalResults". See here

How can I get the result of a query that has a TotalResult property?

+4
source share
3 answers

If you execute LuceneQuery, you get a returned DocumentQuery that has a QueryResult property that contains TotalResults, so you can access it like this:

 var documentQuery = (from mdl in query dbSession.LuceneQuery<MyModel>("MyIndex") orderby mdl.Name select dept).Skip(page.Value).Take(4); var totalResults = documentQuery.QueryResult.TotalResults; 

If you are executing a LINQ query, then you can call Count () on the query before restricting it by clicking the Skip and Take buttons:

 var linqQuery = (from mdl in query dbSession.Query<MyModel>("MyIndex") orderby mdl.Name select dept); var totalResults = linqQuery.Count(); var pageOfResults = linqQuery.Skip(page.Value).Take(4); 
+6
source

You need to do something like this at the end of your request

 .Customize(x => x.TotalResult) 

The TotalResult property is available only in LuceneQuery, not in a LINQ query.

0
source

It seems you can get QueryResult via session.LuceneQuery<YouModel>("YourIndex") and not from session.Query<YourModel>("YourIndex") . But, interestingly, why use session.Query<YourModel>("YourIndex") ?

0
source

All Articles