Query interface and pagination

14 messages Options
Embed this post
Permalink
Rob van der Linden Vooren

Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hi,

I'm using the query classes in order to search my content.
I'd like to paginate my results. Assume the search for "my keywords" results in 100 hits, of which I would like to show the first 10 results.
In order to achieve this, suppose I'm using the following code snippet:

HstQuery query = getQueryManager().createQuery(requestContext, scope, filterBean);
Filter filter = query.createFilter();
filter.addContains(".", "my keywords");
query.setFilter(filter);
query.setOffset(0);
query.setLimit(10);
HstQuery queryResult = query.execute();

At this point, I get in trouble when trying to paginate my results.
In particular I need the following information:

- the total number of results

Where to get it? I would expect to be able to do something such as:

queryResult.getTotalResultSize()

But there is no such thing; Any hints on where to find it?

Cheers,

--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Jeroen Reijn

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hi Rob,

yes that's possible. Try:

HippoBeanIterator hits = queryResult.getHippoBeans();        hits.getSize();

That should be it.

Regards,

Jeroen


Rob van der Linden Vooren wrote:

> Hi,
>
> I'm using the query classes in order to search my content.
> I'd like to paginate my results. Assume the search for "my keywords"
> results in 100 hits, of which I would like to show the first 10 results.
> In order to achieve this, suppose I'm using the following code snippet:
>
> HstQuery query = getQueryManager().createQuery(requestContext, scope,
> filterBean);
> Filter filter = query.createFilter();
> filter.addContains(".", "my keywords");
> query.setFilter(filter);
> query.setOffset(0);
> query.setLimit(10);
> HstQuery queryResult = query.execute();
>
> At this point, I get in trouble when trying to paginate my results.
> In particular I need the following information:
>
> - the total number of results
>
> Where to get it? I would expect to be able to do something such as:
>
> queryResult.getTotalResultSize()
>
> But there is no such thing; Any hints on where to find it?
>
> Cheers,
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T:
> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
> General conditions apply
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Rob van der Linden Vooren

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hi Jeroen,

If it was only that simple ;-)
Your code returns the size of the limited subset of the total set paginated. So in my code example returns '10'.

However, debugging shows me the xpath query executed against the repository.
Executing this same query through the repository util -as I call it- I can see the the total number of results is correct.

So my question remains..
May no such method be provided right now, can you guys provide it?

Cheers

On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]> wrote:
Hi Rob,

yes that's possible. Try:

HippoBeanIterator hits = queryResult.getHippoBeans();        hits.getSize();

That should be it.

Regards,

Jeroen



Rob van der Linden Vooren wrote:
Hi,

I'm using the query classes in order to search my content.
I'd like to paginate my results. Assume the search for "my keywords" results in 100 hits, of which I would like to show the first 10 results.
In order to achieve this, suppose I'm using the following code snippet:

HstQuery query = getQueryManager().createQuery(requestContext, scope, filterBean);
Filter filter = query.createFilter();
filter.addContains(".", "my keywords");
query.setFilter(filter);
query.setOffset(0);
query.setLimit(10);
HstQuery queryResult = query.execute();

At this point, I get in trouble when trying to paginate my results.
In particular I need the following information:

- the total number of results

Where to get it? I would expect to be able to do something such as:

queryResult.getTotalResultSize()

But there is no such thing; Any hints on where to find it?

Cheers,

--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
General conditions apply


------------------------------------------------------------------------

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html



--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hello Rob,

On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
<[hidden email]> wrote:

> Hi Jeroen,
>
> If it was only that simple ;-)
> Your code returns the size of the limited subset of the total set paginated.
> So in my code example returns '10'.
>
> However, debugging shows me the xpath query executed against the repository.
> Executing this same query through the repository util -as I call it- I can
> see the the total number of results is correct.
>
> So my question remains..
> May no such method be provided right now, can you guys provide it?

It is already there, only, it needs to be documented better:

If you use setLimit(3), you will get at most 3 hits. Never more. When
you ask the getSize() from the queryResult, you'll get at most 3. Even
if the to the search criteria matched hundreds of documents. If you
use offset(10) and no limit, you'll get for the getSize, just 10 hits
less then without the offset.

This limit is there to be used for performance, and suits for example
very well the : show last 3 agenda items on homepage.

Now, if you need paging & only want 10 results, you do not use the
setLimit. (in jsr-283 i think there are again some methods added to
the api for this, but jackrabbit is still jsr-170).

What you do use, is just the query without setLimit. Then you'll get
back a queryResult, from which you get a HippoBeanIterator. This is a
normal iterator, with some extensions. A very important one is :
skip(int skipNum)

>From the HippoBeanIterator, you can simply iterate the beans you need:
make sure you use skip to jump to the correct place (if current page =
11 and pagesize = 20, skipNum to 220).

Then, you simple fill your List<HippoBean> in a for loop from skipNum
- skipNum + pageSize

There is a forge project example of this

Regards Ard

ps for those familiar to repository 1 in combination with slide, the
set limit now thus works differently

>
> Cheers
>
> On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]> wrote:
>>
>> Hi Rob,
>>
>> yes that's possible. Try:
>>
>> HippoBeanIterator hits = queryResult.getHippoBeans();
>>  hits.getSize();
>>
>> That should be it.
>>
>> Regards,
>>
>> Jeroen
>>
>>
>> Rob van der Linden Vooren wrote:
>>>
>>> Hi,
>>>
>>> I'm using the query classes in order to search my content.
>>> I'd like to paginate my results. Assume the search for "my keywords"
>>> results in 100 hits, of which I would like to show the first 10 results.
>>> In order to achieve this, suppose I'm using the following code snippet:
>>>
>>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>>> filterBean);
>>> Filter filter = query.createFilter();
>>> filter.addContains(".", "my keywords");
>>> query.setFilter(filter);
>>> query.setOffset(0);
>>> query.setLimit(10);
>>> HstQuery queryResult = query.execute();
>>>
>>> At this point, I get in trouble when trying to paginate my results.
>>> In particular I need the following information:
>>>
>>> - the total number of results
>>>
>>> Where to get it? I would expect to be able to do something such as:
>>>
>>> queryResult.getTotalResultSize()
>>>
>>> But there is no such thing; Any hints on where to find it?
>>>
>>> Cheers,
>>>
>>> --
>>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> General conditions apply
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Rob van der Linden Vooren

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hi Ard,

If I understand correctly, what you are saying is:

1. If you want to paginate, query for all results and use the skipNum() method to do pagination.
2. If you want to show a top list, query with limit

This means all of the results have to be mapped from nodes to HippoBeans and iterated over in memory.
This has *serious* consequences with regards to space and time characteristics of creating a paged result. On a larger resultset and I cannot imagine this is something I would want to do.

With that out of the way, I would still need a way to get the total results. As I mentioned, debugging through the source I see that the query fired when using offset/limit is still a query for all results; Therefore I assume that you only map the subset of the total nodes found based on offset/limit parameters set on the query. If this is the case, wouldn't it be possible to record the total number of nodes and expose these through the queryresult? This would be ideal.

Awaiting your response,

Cheers

On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]> wrote:
Hello Rob,

On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi Jeroen,
>
> If it was only that simple ;-)
> Your code returns the size of the limited subset of the total set paginated.
> So in my code example returns '10'.
>
> However, debugging shows me the xpath query executed against the repository.
> Executing this same query through the repository util -as I call it- I can
> see the the total number of results is correct.
>
> So my question remains..
> May no such method be provided right now, can you guys provide it?

It is already there, only, it needs to be documented better:

If you use setLimit(3), you will get at most 3 hits. Never more. When
you ask the getSize() from the queryResult, you'll get at most 3. Even
if the to the search criteria matched hundreds of documents. If you
use offset(10) and no limit, you'll get for the getSize, just 10 hits
less then without the offset.

This limit is there to be used for performance, and suits for example
very well the : show last 3 agenda items on homepage.

Now, if you need paging & only want 10 results, you do not use the
setLimit. (in jsr-283 i think there are again some methods added to
the api for this, but jackrabbit is still jsr-170).

What you do use, is just the query without setLimit. Then you'll get
back a queryResult, from which you get a HippoBeanIterator. This is a
normal iterator, with some extensions. A very important one is :
skip(int skipNum)

>From the HippoBeanIterator, you can simply iterate the beans you need:
make sure you use skip to jump to the correct place (if current page =
11 and pagesize = 20, skipNum to 220).

Then, you simple fill your List<HippoBean> in a for loop from skipNum
- skipNum + pageSize

There is a forge project example of this

Regards Ard

ps for those familiar to repository 1 in combination with slide, the
set limit now thus works differently

>
> Cheers
>
> On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]> wrote:
>>
>> Hi Rob,
>>
>> yes that's possible. Try:
>>
>> HippoBeanIterator hits = queryResult.getHippoBeans();
>>  hits.getSize();
>>
>> That should be it.
>>
>> Regards,
>>
>> Jeroen
>>
>>
>> Rob van der Linden Vooren wrote:
>>>
>>> Hi,
>>>
>>> I'm using the query classes in order to search my content.
>>> I'd like to paginate my results. Assume the search for "my keywords"
>>> results in 100 hits, of which I would like to show the first 10 results.
>>> In order to achieve this, suppose I'm using the following code snippet:
>>>
>>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>>> filterBean);
>>> Filter filter = query.createFilter();
>>> filter.addContains(".", "my keywords");
>>> query.setFilter(filter);
>>> query.setOffset(0);
>>> query.setLimit(10);
>>> HstQuery queryResult = query.execute();
>>>
>>> At this point, I get in trouble when trying to paginate my results.
>>> In particular I need the following information:
>>>
>>> - the total number of results
>>>
>>> Where to get it? I would expect to be able to do something such as:
>>>
>>> queryResult.getTotalResultSize()
>>>
>>> But there is no such thing; Any hints on where to find it?
>>>
>>> Cheers,
>>>
>>> --
>>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> General conditions apply
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html



--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Rob van der Linden Vooren

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
Hi,

Unless offcourse the iterator is a proxy ...

Cheers

On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren <[hidden email]> wrote:
Hi Ard,

If I understand correctly, what you are saying is:

1. If you want to paginate, query for all results and use the skipNum() method to do pagination.
2. If you want to show a top list, query with limit

This means all of the results have to be mapped from nodes to HippoBeans and iterated over in memory.
This has *serious* consequences with regards to space and time characteristics of creating a paged result. On a larger resultset and I cannot imagine this is something I would want to do.

With that out of the way, I would still need a way to get the total results. As I mentioned, debugging through the source I see that the query fired when using offset/limit is still a query for all results; Therefore I assume that you only map the subset of the total nodes found based on offset/limit parameters set on the query. If this is the case, wouldn't it be possible to record the total number of nodes and expose these through the queryresult? This would be ideal.

Awaiting your response,

Cheers


On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]> wrote:
Hello Rob,

On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi Jeroen,
>
> If it was only that simple ;-)
> Your code returns the size of the limited subset of the total set paginated.
> So in my code example returns '10'.
>
> However, debugging shows me the xpath query executed against the repository.
> Executing this same query through the repository util -as I call it- I can
> see the the total number of results is correct.
>
> So my question remains..
> May no such method be provided right now, can you guys provide it?

It is already there, only, it needs to be documented better:

If you use setLimit(3), you will get at most 3 hits. Never more. When
you ask the getSize() from the queryResult, you'll get at most 3. Even
if the to the search criteria matched hundreds of documents. If you
use offset(10) and no limit, you'll get for the getSize, just 10 hits
less then without the offset.

This limit is there to be used for performance, and suits for example
very well the : show last 3 agenda items on homepage.

Now, if you need paging & only want 10 results, you do not use the
setLimit. (in jsr-283 i think there are again some methods added to
the api for this, but jackrabbit is still jsr-170).

What you do use, is just the query without setLimit. Then you'll get
back a queryResult, from which you get a HippoBeanIterator. This is a
normal iterator, with some extensions. A very important one is :
skip(int skipNum)

>From the HippoBeanIterator, you can simply iterate the beans you need:
make sure you use skip to jump to the correct place (if current page =
11 and pagesize = 20, skipNum to 220).

Then, you simple fill your List<HippoBean> in a for loop from skipNum
- skipNum + pageSize

There is a forge project example of this

Regards Ard

ps for those familiar to repository 1 in combination with slide, the
set limit now thus works differently

>
> Cheers
>
> On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]> wrote:
>>
>> Hi Rob,
>>
>> yes that's possible. Try:
>>
>> HippoBeanIterator hits = queryResult.getHippoBeans();
>>  hits.getSize();
>>
>> That should be it.
>>
>> Regards,
>>
>> Jeroen
>>
>>
>> Rob van der Linden Vooren wrote:
>>>
>>> Hi,
>>>
>>> I'm using the query classes in order to search my content.
>>> I'd like to paginate my results. Assume the search for "my keywords"
>>> results in 100 hits, of which I would like to show the first 10 results.
>>> In order to achieve this, suppose I'm using the following code snippet:
>>>
>>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>>> filterBean);
>>> Filter filter = query.createFilter();
>>> filter.addContains(".", "my keywords");
>>> query.setFilter(filter);
>>> query.setOffset(0);
>>> query.setLimit(10);
>>> HstQuery queryResult = query.execute();
>>>
>>> At this point, I get in trouble when trying to paginate my results.
>>> In particular I need the following information:
>>>
>>> - the total number of results
>>>
>>> Where to get it? I would expect to be able to do something such as:
>>>
>>> queryResult.getTotalResultSize()
>>>
>>> But there is no such thing; Any hints on where to find it?
>>>
>>> Cheers,
>>>
>>> --
>>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> General conditions apply
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html



--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply




--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Rob van der Linden Vooren
On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
<[hidden email]> wrote:

> Hi Ard,
>
> If I understand correctly, what you are saying is:
>
> 1. If you want to paginate, query for all results and use the skipNum()
> method to do pagination.
> 2. If you want to show a top list, query with limit
>
> This means all of the results have to be mapped from nodes to HippoBeans and
> iterated over in memory.

No, the skip is propagated to the jcr NodeIterator. Therefor, if you
want to display item 100-110, if you use skip(100), still only 10
beans will be created. Also the jcr nodes for beans 0-99 are not
fetched.

> This has *serious* consequences with regards to space and time
> characteristics of creating a paged result. On a larger resultset and I
> cannot imagine this is something I would want to do.

as i explained, i am not doing so, and, indeed, i do not want to :-)
Hence the skip method...

>
> With that out of the way, I would still need a way to get the total results.

Yes, just do the getSize(). The getSize() on the the
HstQueryResultImpl or on the HippoBeanIteratorImpl does not actually
populate the entire iterator with HippoBeans...it is a call through
the jcr NodeIterator, which in JackRabbit is some lazy loading
iterator, and, where the getSize is propagated to the executed query,
without fetching actual nodes.

The current drawback, is that to do correct counting, you need to know
whether you have read access on the lucene hit, hence the
accessmanager is called. As we have authorisation which can be
translated into a lucene query, we can bypass this in the end, and
have correct counts directly out of the lucene query (authorized
counting with no latency is quite cool!)

> As I mentioned, debugging through the source I see that the query fired when
> using offset/limit is still a query for all results; Therefore I assume that

Without having all results over the line...it is all lazy....

> you only map the subset of the total nodes found based on offset/limit
> parameters set on the query. If this is the case, wouldn't it be possible to
> record the total number of nodes and expose these through the queryresult?
> This would be ideal.

I hope I convinced you by now that I have given it enough thoughts
:-)) Even authorized counting will become blistering fast, don't worry
about this part of performance, I have it covered :-))...unless you
iterate through the HippoBeanIterator through 1 million nodes and
forgot about the skip....but then i can at least make you very happy
the you can use skip to improve your performance enormously.

I don't mind to dive into deeper discussions, why, while keeping the
number of fetched nodes constant, that fetching the first 10 will
always be a little faster then number 100-110, which again will be
faster then 100.000 - 100.010, though, there is nothing to strange
about this, but just lucene and jackrabbit internals, where these kind
of subtle slowdowns happen in i think any system.

Hope this clarifies things a little

Ard

>
> Awaiting your response,
>
> Cheers
>
> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]>
> wrote:
>>
>> Hello Rob,
>>
>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>> <[hidden email]> wrote:
>> > Hi Jeroen,
>> >
>> > If it was only that simple ;-)
>> > Your code returns the size of the limited subset of the total set
>> > paginated.
>> > So in my code example returns '10'.
>> >
>> > However, debugging shows me the xpath query executed against the
>> > repository.
>> > Executing this same query through the repository util -as I call it- I
>> > can
>> > see the the total number of results is correct.
>> >
>> > So my question remains..
>> > May no such method be provided right now, can you guys provide it?
>>
>> It is already there, only, it needs to be documented better:
>>
>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>> if the to the search criteria matched hundreds of documents. If you
>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>> less then without the offset.
>>
>> This limit is there to be used for performance, and suits for example
>> very well the : show last 3 agenda items on homepage.
>>
>> Now, if you need paging & only want 10 results, you do not use the
>> setLimit. (in jsr-283 i think there are again some methods added to
>> the api for this, but jackrabbit is still jsr-170).
>>
>> What you do use, is just the query without setLimit. Then you'll get
>> back a queryResult, from which you get a HippoBeanIterator. This is a
>> normal iterator, with some extensions. A very important one is :
>> skip(int skipNum)
>>
>> >From the HippoBeanIterator, you can simply iterate the beans you need:
>> make sure you use skip to jump to the correct place (if current page =
>> 11 and pagesize = 20, skipNum to 220).
>>
>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>> - skipNum + pageSize
>>
>> There is a forge project example of this
>>
>> Regards Ard
>>
>> ps for those familiar to repository 1 in combination with slide, the
>> set limit now thus works differently
>>
>> >
>> > Cheers
>> >
>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>> > wrote:
>> >>
>> >> Hi Rob,
>> >>
>> >> yes that's possible. Try:
>> >>
>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>> >>  hits.getSize();
>> >>
>> >> That should be it.
>> >>
>> >> Regards,
>> >>
>> >> Jeroen
>> >>
>> >>
>> >> Rob van der Linden Vooren wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> I'm using the query classes in order to search my content.
>> >>> I'd like to paginate my results. Assume the search for "my keywords"
>> >>> results in 100 hits, of which I would like to show the first 10
>> >>> results.
>> >>> In order to achieve this, suppose I'm using the following code
>> >>> snippet:
>> >>>
>> >>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>> >>> filterBean);
>> >>> Filter filter = query.createFilter();
>> >>> filter.addContains(".", "my keywords");
>> >>> query.setFilter(filter);
>> >>> query.setOffset(0);
>> >>> query.setLimit(10);
>> >>> HstQuery queryResult = query.execute();
>> >>>
>> >>> At this point, I get in trouble when trying to paginate my results.
>> >>> In particular I need the following information:
>> >>>
>> >>> - the total number of results
>> >>>
>> >>> Where to get it? I would expect to be able to do something such as:
>> >>>
>> >>> queryResult.getTotalResultSize()
>> >>>
>> >>> But there is no such thing; Any hints on where to find it?
>> >>>
>> >>> Cheers,
>> >>>
>> >>> --
>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>> >>> General conditions apply
>> >>>
>> >>>
>> >>>
>> >>> ------------------------------------------------------------------------
>> >>>
>> >>> _______________________________________________
>> >>> Hippo-cms7-user mailing list and forums
>> >>> http://www.onehippo.org/cms7/support/community.html
>> >>
>> >> _______________________________________________
>> >> Hippo-cms7-user mailing list and forums
>> >> http://www.onehippo.org/cms7/support/community.html
>> >
>> >
>> >
>> > --
>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> > +31(0)2-04862036
>> > | www.jteam.nl
>> > General conditions apply
>> >
>> >
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/community.html
>> >
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Rob van der Linden Vooren
On Thu, Jun 4, 2009 at 4:04 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi,
>
> Unless offcourse the iterator is a proxy ...

If I would have read this second mail before, it would have spared my
quite some time by answering yes :-(((((



>
> Cheers
>
> On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren <[hidden email]>
> wrote:
>>
>> Hi Ard,
>>
>> If I understand correctly, what you are saying is:
>>
>> 1. If you want to paginate, query for all results and use the skipNum()
>> method to do pagination.
>> 2. If you want to show a top list, query with limit
>>
>> This means all of the results have to be mapped from nodes to HippoBeans
>> and iterated over in memory.
>> This has *serious* consequences with regards to space and time
>> characteristics of creating a paged result. On a larger resultset and I
>> cannot imagine this is something I would want to do.
>>
>> With that out of the way, I would still need a way to get the total
>> results. As I mentioned, debugging through the source I see that the query
>> fired when using offset/limit is still a query for all results; Therefore I
>> assume that you only map the subset of the total nodes found based on
>> offset/limit parameters set on the query. If this is the case, wouldn't it
>> be possible to record the total number of nodes and expose these through the
>> queryresult? This would be ideal.
>>
>> Awaiting your response,
>>
>> Cheers
>>
>> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]>
>> wrote:
>>>
>>> Hello Rob,
>>>
>>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>>> <[hidden email]> wrote:
>>> > Hi Jeroen,
>>> >
>>> > If it was only that simple ;-)
>>> > Your code returns the size of the limited subset of the total set
>>> > paginated.
>>> > So in my code example returns '10'.
>>> >
>>> > However, debugging shows me the xpath query executed against the
>>> > repository.
>>> > Executing this same query through the repository util -as I call it- I
>>> > can
>>> > see the the total number of results is correct.
>>> >
>>> > So my question remains..
>>> > May no such method be provided right now, can you guys provide it?
>>>
>>> It is already there, only, it needs to be documented better:
>>>
>>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>>> if the to the search criteria matched hundreds of documents. If you
>>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>>> less then without the offset.
>>>
>>> This limit is there to be used for performance, and suits for example
>>> very well the : show last 3 agenda items on homepage.
>>>
>>> Now, if you need paging & only want 10 results, you do not use the
>>> setLimit. (in jsr-283 i think there are again some methods added to
>>> the api for this, but jackrabbit is still jsr-170).
>>>
>>> What you do use, is just the query without setLimit. Then you'll get
>>> back a queryResult, from which you get a HippoBeanIterator. This is a
>>> normal iterator, with some extensions. A very important one is :
>>> skip(int skipNum)
>>>
>>> >From the HippoBeanIterator, you can simply iterate the beans you need:
>>> make sure you use skip to jump to the correct place (if current page =
>>> 11 and pagesize = 20, skipNum to 220).
>>>
>>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>>> - skipNum + pageSize
>>>
>>> There is a forge project example of this
>>>
>>> Regards Ard
>>>
>>> ps for those familiar to repository 1 in combination with slide, the
>>> set limit now thus works differently
>>>
>>> >
>>> > Cheers
>>> >
>>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>>> > wrote:
>>> >>
>>> >> Hi Rob,
>>> >>
>>> >> yes that's possible. Try:
>>> >>
>>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>>> >>  hits.getSize();
>>> >>
>>> >> That should be it.
>>> >>
>>> >> Regards,
>>> >>
>>> >> Jeroen
>>> >>
>>> >>
>>> >> Rob van der Linden Vooren wrote:
>>> >>>
>>> >>> Hi,
>>> >>>
>>> >>> I'm using the query classes in order to search my content.
>>> >>> I'd like to paginate my results. Assume the search for "my keywords"
>>> >>> results in 100 hits, of which I would like to show the first 10
>>> >>> results.
>>> >>> In order to achieve this, suppose I'm using the following code
>>> >>> snippet:
>>> >>>
>>> >>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>>> >>> filterBean);
>>> >>> Filter filter = query.createFilter();
>>> >>> filter.addContains(".", "my keywords");
>>> >>> query.setFilter(filter);
>>> >>> query.setOffset(0);
>>> >>> query.setLimit(10);
>>> >>> HstQuery queryResult = query.execute();
>>> >>>
>>> >>> At this point, I get in trouble when trying to paginate my results.
>>> >>> In particular I need the following information:
>>> >>>
>>> >>> - the total number of results
>>> >>>
>>> >>> Where to get it? I would expect to be able to do something such as:
>>> >>>
>>> >>> queryResult.getTotalResultSize()
>>> >>>
>>> >>> But there is no such thing; Any hints on where to find it?
>>> >>>
>>> >>> Cheers,
>>> >>>
>>> >>> --
>>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> >>> General conditions apply
>>> >>>
>>> >>>
>>> >>>
>>> >>> ------------------------------------------------------------------------
>>> >>>
>>> >>> _______________________________________________
>>> >>> Hippo-cms7-user mailing list and forums
>>> >>> http://www.onehippo.org/cms7/support/community.html
>>> >>
>>> >> _______________________________________________
>>> >> Hippo-cms7-user mailing list and forums
>>> >> http://www.onehippo.org/cms7/support/community.html
>>> >
>>> >
>>> >
>>> > --
>>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> > +31(0)2-04862036
>>> > | www.jteam.nl
>>> > General conditions apply
>>> >
>>> >
>>> > _______________________________________________
>>> > Hippo-cms7-user mailing list and forums
>>> > http://www.onehippo.org/cms7/support/community.html
>>> >
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>>
>>
>> --
>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> +31(0)2-04862036 | www.jteam.nl
>> General conditions apply
>>
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Rob van der Linden Vooren

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Ard
Hi Ard,

Thanks for your thorough and clarifying explanation.
Im rest assured that it is thought out well.

Cheers,

Rob

On Thu, Jun 4, 2009 at 4:10 PM, Ard Schrijvers <[hidden email]> wrote:
On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi Ard,
>
> If I understand correctly, what you are saying is:
>
> 1. If you want to paginate, query for all results and use the skipNum()
> method to do pagination.
> 2. If you want to show a top list, query with limit
>
> This means all of the results have to be mapped from nodes to HippoBeans and
> iterated over in memory.

No, the skip is propagated to the jcr NodeIterator. Therefor, if you
want to display item 100-110, if you use skip(100), still only 10
beans will be created. Also the jcr nodes for beans 0-99 are not
fetched.

> This has *serious* consequences with regards to space and time
> characteristics of creating a paged result. On a larger resultset and I
> cannot imagine this is something I would want to do.

as i explained, i am not doing so, and, indeed, i do not want to :-)
Hence the skip method...

>
> With that out of the way, I would still need a way to get the total results.

Yes, just do the getSize(). The getSize() on the the
HstQueryResultImpl or on the HippoBeanIteratorImpl does not actually
populate the entire iterator with HippoBeans...it is a call through
the jcr NodeIterator, which in JackRabbit is some lazy loading
iterator, and, where the getSize is propagated to the executed query,
without fetching actual nodes.

The current drawback, is that to do correct counting, you need to know
whether you have read access on the lucene hit, hence the
accessmanager is called. As we have authorisation which can be
translated into a lucene query, we can bypass this in the end, and
have correct counts directly out of the lucene query (authorized
counting with no latency is quite cool!)

> As I mentioned, debugging through the source I see that the query fired when
> using offset/limit is still a query for all results; Therefore I assume that

Without having all results over the line...it is all lazy....

> you only map the subset of the total nodes found based on offset/limit
> parameters set on the query. If this is the case, wouldn't it be possible to
> record the total number of nodes and expose these through the queryresult?
> This would be ideal.

I hope I convinced you by now that I have given it enough thoughts
:-)) Even authorized counting will become blistering fast, don't worry
about this part of performance, I have it covered :-))...unless you
iterate through the HippoBeanIterator through 1 million nodes and
forgot about the skip....but then i can at least make you very happy
the you can use skip to improve your performance enormously.

I don't mind to dive into deeper discussions, why, while keeping the
number of fetched nodes constant, that fetching the first 10 will
always be a little faster then number 100-110, which again will be
faster then 100.000 - 100.010, though, there is nothing to strange
about this, but just lucene and jackrabbit internals, where these kind
of subtle slowdowns happen in i think any system.

Hope this clarifies things a little

Ard

>
> Awaiting your response,
>
> Cheers
>
> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]>
> wrote:
>>
>> Hello Rob,
>>
>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>> <[hidden email]> wrote:
>> > Hi Jeroen,
>> >
>> > If it was only that simple ;-)
>> > Your code returns the size of the limited subset of the total set
>> > paginated.
>> > So in my code example returns '10'.
>> >
>> > However, debugging shows me the xpath query executed against the
>> > repository.
>> > Executing this same query through the repository util -as I call it- I
>> > can
>> > see the the total number of results is correct.
>> >
>> > So my question remains..
>> > May no such method be provided right now, can you guys provide it?
>>
>> It is already there, only, it needs to be documented better:
>>
>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>> if the to the search criteria matched hundreds of documents. If you
>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>> less then without the offset.
>>
>> This limit is there to be used for performance, and suits for example
>> very well the : show last 3 agenda items on homepage.
>>
>> Now, if you need paging & only want 10 results, you do not use the
>> setLimit. (in jsr-283 i think there are again some methods added to
>> the api for this, but jackrabbit is still jsr-170).
>>
>> What you do use, is just the query without setLimit. Then you'll get
>> back a queryResult, from which you get a HippoBeanIterator. This is a
>> normal iterator, with some extensions. A very important one is :
>> skip(int skipNum)
>>
>> >From the HippoBeanIterator, you can simply iterate the beans you need:
>> make sure you use skip to jump to the correct place (if current page =
>> 11 and pagesize = 20, skipNum to 220).
>>
>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>> - skipNum + pageSize
>>
>> There is a forge project example of this
>>
>> Regards Ard
>>
>> ps for those familiar to repository 1 in combination with slide, the
>> set limit now thus works differently
>>
>> >
>> > Cheers
>> >
>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>> > wrote:
>> >>
>> >> Hi Rob,
>> >>
>> >> yes that's possible. Try:
>> >>
>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>> >>  hits.getSize();
>> >>
>> >> That should be it.
>> >>
>> >> Regards,
>> >>
>> >> Jeroen
>> >>
>> >>
>> >> Rob van der Linden Vooren wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> I'm using the query classes in order to search my content.
>> >>> I'd like to paginate my results. Assume the search for "my keywords"
>> >>> results in 100 hits, of which I would like to show the first 10
>> >>> results.
>> >>> In order to achieve this, suppose I'm using the following code
>> >>> snippet:
>> >>>
>> >>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>> >>> filterBean);
>> >>> Filter filter = query.createFilter();
>> >>> filter.addContains(".", "my keywords");
>> >>> query.setFilter(filter);
>> >>> query.setOffset(0);
>> >>> query.setLimit(10);
>> >>> HstQuery queryResult = query.execute();
>> >>>
>> >>> At this point, I get in trouble when trying to paginate my results.
>> >>> In particular I need the following information:
>> >>>
>> >>> - the total number of results
>> >>>
>> >>> Where to get it? I would expect to be able to do something such as:
>> >>>
>> >>> queryResult.getTotalResultSize()
>> >>>
>> >>> But there is no such thing; Any hints on where to find it?
>> >>>
>> >>> Cheers,
>> >>>
>> >>> --
>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>> >>> General conditions apply
>> >>>
>> >>>
>> >>>
>> >>> ------------------------------------------------------------------------
>> >>>
>> >>> _______________________________________________
>> >>> Hippo-cms7-user mailing list and forums
>> >>> http://www.onehippo.org/cms7/support/community.html
>> >>
>> >> _______________________________________________
>> >> Hippo-cms7-user mailing list and forums
>> >> http://www.onehippo.org/cms7/support/community.html
>> >
>> >
>> >
>> > --
>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> > +31(0)2-04862036
>> > | www.jteam.nl
>> > General conditions apply
>> >
>> >
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/community.html
>> >
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html



--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Rob van der Linden Vooren

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Ard
Hi Ard,

On the upside, you can now pretty much copy/paste the answer to my question as documentation ;-).

Cheers, Rob


On Thu, Jun 4, 2009 at 4:12 PM, Ard Schrijvers <[hidden email]> wrote:
On Thu, Jun 4, 2009 at 4:04 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi,
>
> Unless offcourse the iterator is a proxy ...

If I would have read this second mail before, it would have spared my
quite some time by answering yes :-(((((



>
> Cheers
>
> On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren <[hidden email]>
> wrote:
>>
>> Hi Ard,
>>
>> If I understand correctly, what you are saying is:
>>
>> 1. If you want to paginate, query for all results and use the skipNum()
>> method to do pagination.
>> 2. If you want to show a top list, query with limit
>>
>> This means all of the results have to be mapped from nodes to HippoBeans
>> and iterated over in memory.
>> This has *serious* consequences with regards to space and time
>> characteristics of creating a paged result. On a larger resultset and I
>> cannot imagine this is something I would want to do.
>>
>> With that out of the way, I would still need a way to get the total
>> results. As I mentioned, debugging through the source I see that the query
>> fired when using offset/limit is still a query for all results; Therefore I
>> assume that you only map the subset of the total nodes found based on
>> offset/limit parameters set on the query. If this is the case, wouldn't it
>> be possible to record the total number of nodes and expose these through the
>> queryresult? This would be ideal.
>>
>> Awaiting your response,
>>
>> Cheers
>>
>> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers <[hidden email]>
>> wrote:
>>>
>>> Hello Rob,
>>>
>>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>>> <[hidden email]> wrote:
>>> > Hi Jeroen,
>>> >
>>> > If it was only that simple ;-)
>>> > Your code returns the size of the limited subset of the total set
>>> > paginated.
>>> > So in my code example returns '10'.
>>> >
>>> > However, debugging shows me the xpath query executed against the
>>> > repository.
>>> > Executing this same query through the repository util -as I call it- I
>>> > can
>>> > see the the total number of results is correct.
>>> >
>>> > So my question remains..
>>> > May no such method be provided right now, can you guys provide it?
>>>
>>> It is already there, only, it needs to be documented better:
>>>
>>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>>> if the to the search criteria matched hundreds of documents. If you
>>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>>> less then without the offset.
>>>
>>> This limit is there to be used for performance, and suits for example
>>> very well the : show last 3 agenda items on homepage.
>>>
>>> Now, if you need paging & only want 10 results, you do not use the
>>> setLimit. (in jsr-283 i think there are again some methods added to
>>> the api for this, but jackrabbit is still jsr-170).
>>>
>>> What you do use, is just the query without setLimit. Then you'll get
>>> back a queryResult, from which you get a HippoBeanIterator. This is a
>>> normal iterator, with some extensions. A very important one is :
>>> skip(int skipNum)
>>>
>>> >From the HippoBeanIterator, you can simply iterate the beans you need:
>>> make sure you use skip to jump to the correct place (if current page =
>>> 11 and pagesize = 20, skipNum to 220).
>>>
>>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>>> - skipNum + pageSize
>>>
>>> There is a forge project example of this
>>>
>>> Regards Ard
>>>
>>> ps for those familiar to repository 1 in combination with slide, the
>>> set limit now thus works differently
>>>
>>> >
>>> > Cheers
>>> >
>>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>>> > wrote:
>>> >>
>>> >> Hi Rob,
>>> >>
>>> >> yes that's possible. Try:
>>> >>
>>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>>> >>  hits.getSize();
>>> >>
>>> >> That should be it.
>>> >>
>>> >> Regards,
>>> >>
>>> >> Jeroen
>>> >>
>>> >>
>>> >> Rob van der Linden Vooren wrote:
>>> >>>
>>> >>> Hi,
>>> >>>
>>> >>> I'm using the query classes in order to search my content.
>>> >>> I'd like to paginate my results. Assume the search for "my keywords"
>>> >>> results in 100 hits, of which I would like to show the first 10
>>> >>> results.
>>> >>> In order to achieve this, suppose I'm using the following code
>>> >>> snippet:
>>> >>>
>>> >>> HstQuery query = getQueryManager().createQuery(requestContext, scope,
>>> >>> filterBean);
>>> >>> Filter filter = query.createFilter();
>>> >>> filter.addContains(".", "my keywords");
>>> >>> query.setFilter(filter);
>>> >>> query.setOffset(0);
>>> >>> query.setLimit(10);
>>> >>> HstQuery queryResult = query.execute();
>>> >>>
>>> >>> At this point, I get in trouble when trying to paginate my results.
>>> >>> In particular I need the following information:
>>> >>>
>>> >>> - the total number of results
>>> >>>
>>> >>> Where to get it? I would expect to be able to do something such as:
>>> >>>
>>> >>> queryResult.getTotalResultSize()
>>> >>>
>>> >>> But there is no such thing; Any hints on where to find it?
>>> >>>
>>> >>> Cheers,
>>> >>>
>>> >>> --
>>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> >>> General conditions apply
>>> >>>
>>> >>>
>>> >>>
>>> >>> ------------------------------------------------------------------------
>>> >>>
>>> >>> _______________________________________________
>>> >>> Hippo-cms7-user mailing list and forums
>>> >>> http://www.onehippo.org/cms7/support/community.html
>>> >>
>>> >> _______________________________________________
>>> >> Hippo-cms7-user mailing list and forums
>>> >> http://www.onehippo.org/cms7/support/community.html
>>> >
>>> >
>>> >
>>> > --
>>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> > +31(0)2-04862036
>>> > | www.jteam.nl
>>> > General conditions apply
>>> >
>>> >
>>> > _______________________________________________
>>> > Hippo-cms7-user mailing list and forums
>>> > http://www.onehippo.org/cms7/support/community.html
>>> >
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>>
>>
>> --
>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> +31(0)2-04862036 | www.jteam.nl
>> General conditions apply
>>
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html



--
Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036 | www.jteam.nl
General conditions apply


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Rob van der Linden Vooren
On Thu, Jun 4, 2009 at 6:11 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi Ard,
>
> Thanks for your thorough and clarifying explanation.
> Im rest assured that it is thought out well.

I think your question was also quite an important one. The skip on the
'lazy' iterator does the trick, you couldn't have known this...we have
a search forge plugin available showing this behavior.

Regards

>
> Cheers,
>
> Rob
>
> On Thu, Jun 4, 2009 at 4:10 PM, Ard Schrijvers <[hidden email]>
> wrote:
>>
>> On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
>> <[hidden email]> wrote:
>> > Hi Ard,
>> >
>> > If I understand correctly, what you are saying is:
>> >
>> > 1. If you want to paginate, query for all results and use the skipNum()
>> > method to do pagination.
>> > 2. If you want to show a top list, query with limit
>> >
>> > This means all of the results have to be mapped from nodes to HippoBeans
>> > and
>> > iterated over in memory.
>>
>> No, the skip is propagated to the jcr NodeIterator. Therefor, if you
>> want to display item 100-110, if you use skip(100), still only 10
>> beans will be created. Also the jcr nodes for beans 0-99 are not
>> fetched.
>>
>> > This has *serious* consequences with regards to space and time
>> > characteristics of creating a paged result. On a larger resultset and I
>> > cannot imagine this is something I would want to do.
>>
>> as i explained, i am not doing so, and, indeed, i do not want to :-)
>> Hence the skip method...
>>
>> >
>> > With that out of the way, I would still need a way to get the total
>> > results.
>>
>> Yes, just do the getSize(). The getSize() on the the
>> HstQueryResultImpl or on the HippoBeanIteratorImpl does not actually
>> populate the entire iterator with HippoBeans...it is a call through
>> the jcr NodeIterator, which in JackRabbit is some lazy loading
>> iterator, and, where the getSize is propagated to the executed query,
>> without fetching actual nodes.
>>
>> The current drawback, is that to do correct counting, you need to know
>> whether you have read access on the lucene hit, hence the
>> accessmanager is called. As we have authorisation which can be
>> translated into a lucene query, we can bypass this in the end, and
>> have correct counts directly out of the lucene query (authorized
>> counting with no latency is quite cool!)
>>
>> > As I mentioned, debugging through the source I see that the query fired
>> > when
>> > using offset/limit is still a query for all results; Therefore I assume
>> > that
>>
>> Without having all results over the line...it is all lazy....
>>
>> > you only map the subset of the total nodes found based on offset/limit
>> > parameters set on the query. If this is the case, wouldn't it be
>> > possible to
>> > record the total number of nodes and expose these through the
>> > queryresult?
>> > This would be ideal.
>>
>> I hope I convinced you by now that I have given it enough thoughts
>> :-)) Even authorized counting will become blistering fast, don't worry
>> about this part of performance, I have it covered :-))...unless you
>> iterate through the HippoBeanIterator through 1 million nodes and
>> forgot about the skip....but then i can at least make you very happy
>> the you can use skip to improve your performance enormously.
>>
>> I don't mind to dive into deeper discussions, why, while keeping the
>> number of fetched nodes constant, that fetching the first 10 will
>> always be a little faster then number 100-110, which again will be
>> faster then 100.000 - 100.010, though, there is nothing to strange
>> about this, but just lucene and jackrabbit internals, where these kind
>> of subtle slowdowns happen in i think any system.
>>
>> Hope this clarifies things a little
>>
>> Ard
>>
>> >
>> > Awaiting your response,
>> >
>> > Cheers
>> >
>> > On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers
>> > <[hidden email]>
>> > wrote:
>> >>
>> >> Hello Rob,
>> >>
>> >> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>> >> <[hidden email]> wrote:
>> >> > Hi Jeroen,
>> >> >
>> >> > If it was only that simple ;-)
>> >> > Your code returns the size of the limited subset of the total set
>> >> > paginated.
>> >> > So in my code example returns '10'.
>> >> >
>> >> > However, debugging shows me the xpath query executed against the
>> >> > repository.
>> >> > Executing this same query through the repository util -as I call it-
>> >> > I
>> >> > can
>> >> > see the the total number of results is correct.
>> >> >
>> >> > So my question remains..
>> >> > May no such method be provided right now, can you guys provide it?
>> >>
>> >> It is already there, only, it needs to be documented better:
>> >>
>> >> If you use setLimit(3), you will get at most 3 hits. Never more. When
>> >> you ask the getSize() from the queryResult, you'll get at most 3. Even
>> >> if the to the search criteria matched hundreds of documents. If you
>> >> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>> >> less then without the offset.
>> >>
>> >> This limit is there to be used for performance, and suits for example
>> >> very well the : show last 3 agenda items on homepage.
>> >>
>> >> Now, if you need paging & only want 10 results, you do not use the
>> >> setLimit. (in jsr-283 i think there are again some methods added to
>> >> the api for this, but jackrabbit is still jsr-170).
>> >>
>> >> What you do use, is just the query without setLimit. Then you'll get
>> >> back a queryResult, from which you get a HippoBeanIterator. This is a
>> >> normal iterator, with some extensions. A very important one is :
>> >> skip(int skipNum)
>> >>
>> >> >From the HippoBeanIterator, you can simply iterate the beans you need:
>> >> make sure you use skip to jump to the correct place (if current page =
>> >> 11 and pagesize = 20, skipNum to 220).
>> >>
>> >> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>> >> - skipNum + pageSize
>> >>
>> >> There is a forge project example of this
>> >>
>> >> Regards Ard
>> >>
>> >> ps for those familiar to repository 1 in combination with slide, the
>> >> set limit now thus works differently
>> >>
>> >> >
>> >> > Cheers
>> >> >
>> >> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>> >> > wrote:
>> >> >>
>> >> >> Hi Rob,
>> >> >>
>> >> >> yes that's possible. Try:
>> >> >>
>> >> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>> >> >>  hits.getSize();
>> >> >>
>> >> >> That should be it.
>> >> >>
>> >> >> Regards,
>> >> >>
>> >> >> Jeroen
>> >> >>
>> >> >>
>> >> >> Rob van der Linden Vooren wrote:
>> >> >>>
>> >> >>> Hi,
>> >> >>>
>> >> >>> I'm using the query classes in order to search my content.
>> >> >>> I'd like to paginate my results. Assume the search for "my
>> >> >>> keywords"
>> >> >>> results in 100 hits, of which I would like to show the first 10
>> >> >>> results.
>> >> >>> In order to achieve this, suppose I'm using the following code
>> >> >>> snippet:
>> >> >>>
>> >> >>> HstQuery query = getQueryManager().createQuery(requestContext,
>> >> >>> scope,
>> >> >>> filterBean);
>> >> >>> Filter filter = query.createFilter();
>> >> >>> filter.addContains(".", "my keywords");
>> >> >>> query.setFilter(filter);
>> >> >>> query.setOffset(0);
>> >> >>> query.setLimit(10);
>> >> >>> HstQuery queryResult = query.execute();
>> >> >>>
>> >> >>> At this point, I get in trouble when trying to paginate my results.
>> >> >>> In particular I need the following information:
>> >> >>>
>> >> >>> - the total number of results
>> >> >>>
>> >> >>> Where to get it? I would expect to be able to do something such as:
>> >> >>>
>> >> >>> queryResult.getTotalResultSize()
>> >> >>>
>> >> >>> But there is no such thing; Any hints on where to find it?
>> >> >>>
>> >> >>> Cheers,
>> >> >>>
>> >> >>> --
>> >> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>> >> >>> General conditions apply
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> ------------------------------------------------------------------------
>> >> >>>
>> >> >>> _______________________________________________
>> >> >>> Hippo-cms7-user mailing list and forums
>> >> >>> http://www.onehippo.org/cms7/support/community.html
>> >> >>
>> >> >> _______________________________________________
>> >> >> Hippo-cms7-user mailing list and forums
>> >> >> http://www.onehippo.org/cms7/support/community.html
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >> > +31(0)2-04862036
>> >> > | www.jteam.nl
>> >> > General conditions apply
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > Hippo-cms7-user mailing list and forums
>> >> > http://www.onehippo.org/cms7/support/community.html
>> >> >
>> >> _______________________________________________
>> >> Hippo-cms7-user mailing list and forums
>> >> http://www.onehippo.org/cms7/support/community.html
>> >
>> >
>> >
>> > --
>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> > +31(0)2-04862036
>> > | www.jteam.nl
>> > General conditions apply
>> >
>> >
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/community.html
>> >
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
In reply to this post by Rob van der Linden Vooren
On Thu, Jun 4, 2009 at 6:12 PM, Rob van der Linden Vooren
<[hidden email]> wrote:
> Hi Ard,
>
> On the upside, you can now pretty much copy/paste the answer to my question
> as documentation ;-).

I keep hoping somebody else who has knowledge about styling and such
would do this for me...I think we'll find this person on short notice!

In the mean time i am, when i have some spare time, working on the
technical documentation explaining how the hst2 works. Stay tuned

Ard

>
> Cheers, Rob
>
>
> On Thu, Jun 4, 2009 at 4:12 PM, Ard Schrijvers <[hidden email]>
> wrote:
>>
>> On Thu, Jun 4, 2009 at 4:04 PM, Rob van der Linden Vooren
>> <[hidden email]> wrote:
>> > Hi,
>> >
>> > Unless offcourse the iterator is a proxy ...
>>
>> If I would have read this second mail before, it would have spared my
>> quite some time by answering yes :-(((((
>>
>>
>>
>> >
>> > Cheers
>> >
>> > On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
>> > <[hidden email]>
>> > wrote:
>> >>
>> >> Hi Ard,
>> >>
>> >> If I understand correctly, what you are saying is:
>> >>
>> >> 1. If you want to paginate, query for all results and use the skipNum()
>> >> method to do pagination.
>> >> 2. If you want to show a top list, query with limit
>> >>
>> >> This means all of the results have to be mapped from nodes to
>> >> HippoBeans
>> >> and iterated over in memory.
>> >> This has *serious* consequences with regards to space and time
>> >> characteristics of creating a paged result. On a larger resultset and I
>> >> cannot imagine this is something I would want to do.
>> >>
>> >> With that out of the way, I would still need a way to get the total
>> >> results. As I mentioned, debugging through the source I see that the
>> >> query
>> >> fired when using offset/limit is still a query for all results;
>> >> Therefore I
>> >> assume that you only map the subset of the total nodes found based on
>> >> offset/limit parameters set on the query. If this is the case, wouldn't
>> >> it
>> >> be possible to record the total number of nodes and expose these
>> >> through the
>> >> queryresult? This would be ideal.
>> >>
>> >> Awaiting your response,
>> >>
>> >> Cheers
>> >>
>> >> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers
>> >> <[hidden email]>
>> >> wrote:
>> >>>
>> >>> Hello Rob,
>> >>>
>> >>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>> >>> <[hidden email]> wrote:
>> >>> > Hi Jeroen,
>> >>> >
>> >>> > If it was only that simple ;-)
>> >>> > Your code returns the size of the limited subset of the total set
>> >>> > paginated.
>> >>> > So in my code example returns '10'.
>> >>> >
>> >>> > However, debugging shows me the xpath query executed against the
>> >>> > repository.
>> >>> > Executing this same query through the repository util -as I call it-
>> >>> > I
>> >>> > can
>> >>> > see the the total number of results is correct.
>> >>> >
>> >>> > So my question remains..
>> >>> > May no such method be provided right now, can you guys provide it?
>> >>>
>> >>> It is already there, only, it needs to be documented better:
>> >>>
>> >>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>> >>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>> >>> if the to the search criteria matched hundreds of documents. If you
>> >>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>> >>> less then without the offset.
>> >>>
>> >>> This limit is there to be used for performance, and suits for example
>> >>> very well the : show last 3 agenda items on homepage.
>> >>>
>> >>> Now, if you need paging & only want 10 results, you do not use the
>> >>> setLimit. (in jsr-283 i think there are again some methods added to
>> >>> the api for this, but jackrabbit is still jsr-170).
>> >>>
>> >>> What you do use, is just the query without setLimit. Then you'll get
>> >>> back a queryResult, from which you get a HippoBeanIterator. This is a
>> >>> normal iterator, with some extensions. A very important one is :
>> >>> skip(int skipNum)
>> >>>
>> >>> >From the HippoBeanIterator, you can simply iterate the beans you
>> >>> need:
>> >>> make sure you use skip to jump to the correct place (if current page =
>> >>> 11 and pagesize = 20, skipNum to 220).
>> >>>
>> >>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>> >>> - skipNum + pageSize
>> >>>
>> >>> There is a forge project example of this
>> >>>
>> >>> Regards Ard
>> >>>
>> >>> ps for those familiar to repository 1 in combination with slide, the
>> >>> set limit now thus works differently
>> >>>
>> >>> >
>> >>> > Cheers
>> >>> >
>> >>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>> >>> > wrote:
>> >>> >>
>> >>> >> Hi Rob,
>> >>> >>
>> >>> >> yes that's possible. Try:
>> >>> >>
>> >>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>> >>> >>  hits.getSize();
>> >>> >>
>> >>> >> That should be it.
>> >>> >>
>> >>> >> Regards,
>> >>> >>
>> >>> >> Jeroen
>> >>> >>
>> >>> >>
>> >>> >> Rob van der Linden Vooren wrote:
>> >>> >>>
>> >>> >>> Hi,
>> >>> >>>
>> >>> >>> I'm using the query classes in order to search my content.
>> >>> >>> I'd like to paginate my results. Assume the search for "my
>> >>> >>> keywords"
>> >>> >>> results in 100 hits, of which I would like to show the first 10
>> >>> >>> results.
>> >>> >>> In order to achieve this, suppose I'm using the following code
>> >>> >>> snippet:
>> >>> >>>
>> >>> >>> HstQuery query = getQueryManager().createQuery(requestContext,
>> >>> >>> scope,
>> >>> >>> filterBean);
>> >>> >>> Filter filter = query.createFilter();
>> >>> >>> filter.addContains(".", "my keywords");
>> >>> >>> query.setFilter(filter);
>> >>> >>> query.setOffset(0);
>> >>> >>> query.setLimit(10);
>> >>> >>> HstQuery queryResult = query.execute();
>> >>> >>>
>> >>> >>> At this point, I get in trouble when trying to paginate my
>> >>> >>> results.
>> >>> >>> In particular I need the following information:
>> >>> >>>
>> >>> >>> - the total number of results
>> >>> >>>
>> >>> >>> Where to get it? I would expect to be able to do something such
>> >>> >>> as:
>> >>> >>>
>> >>> >>> queryResult.getTotalResultSize()
>> >>> >>>
>> >>> >>> But there is no such thing; Any hints on where to find it?
>> >>> >>>
>> >>> >>> Cheers,
>> >>> >>>
>> >>> >>> --
>> >>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>> >>> >>> General conditions apply
>> >>> >>>
>> >>> >>>
>> >>> >>>
>> >>> >>>
>> >>> >>> ------------------------------------------------------------------------
>> >>> >>>
>> >>> >>> _______________________________________________
>> >>> >>> Hippo-cms7-user mailing list and forums
>> >>> >>> http://www.onehippo.org/cms7/support/community.html
>> >>> >>
>> >>> >> _______________________________________________
>> >>> >> Hippo-cms7-user mailing list and forums
>> >>> >> http://www.onehippo.org/cms7/support/community.html
>> >>> >
>> >>> >
>> >>> >
>> >>> > --
>> >>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >>> > +31(0)2-04862036
>> >>> > | www.jteam.nl
>> >>> > General conditions apply
>> >>> >
>> >>> >
>> >>> > _______________________________________________
>> >>> > Hippo-cms7-user mailing list and forums
>> >>> > http://www.onehippo.org/cms7/support/community.html
>> >>> >
>> >>> _______________________________________________
>> >>> Hippo-cms7-user mailing list and forums
>> >>> http://www.onehippo.org/cms7/support/community.html
>> >>
>> >>
>> >>
>> >> --
>> >> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> >> +31(0)2-04862036 | www.jteam.nl
>> >> General conditions apply
>> >>
>> >
>> >
>> >
>> > --
>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>> > +31(0)2-04862036
>> > | www.jteam.nl
>> > General conditions apply
>> >
>> >
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/community.html
>> >
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
>
>
> --
> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
> | www.jteam.nl
> General conditions apply
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Jasha Joachimsthal

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
2009/6/4 Ard Schrijvers <[hidden email]>:

> On Thu, Jun 4, 2009 at 6:12 PM, Rob van der Linden Vooren
> <[hidden email]> wrote:
>> Hi Ard,
>>
>> On the upside, you can now pretty much copy/paste the answer to my question
>> as documentation ;-).
>
> I keep hoping somebody else who has knowledge about styling and such
> would do this for me...I think we'll find this person on short notice!
>
> In the mean time i am, when i have some spare time, working on the
> technical documentation explaining how the hst2 works. Stay tuned

Something like http://blog.jasha.eu/2009/06/hippo-site-toolkit-query-interface-and.html
? :)

Jasha

>
> Ard
>
>>
>> Cheers, Rob
>>
>>
>> On Thu, Jun 4, 2009 at 4:12 PM, Ard Schrijvers <[hidden email]>
>> wrote:
>>>
>>> On Thu, Jun 4, 2009 at 4:04 PM, Rob van der Linden Vooren
>>> <[hidden email]> wrote:
>>> > Hi,
>>> >
>>> > Unless offcourse the iterator is a proxy ...
>>>
>>> If I would have read this second mail before, it would have spared my
>>> quite some time by answering yes :-(((((
>>>
>>>
>>>
>>> >
>>> > Cheers
>>> >
>>> > On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
>>> > <[hidden email]>
>>> > wrote:
>>> >>
>>> >> Hi Ard,
>>> >>
>>> >> If I understand correctly, what you are saying is:
>>> >>
>>> >> 1. If you want to paginate, query for all results and use the skipNum()
>>> >> method to do pagination.
>>> >> 2. If you want to show a top list, query with limit
>>> >>
>>> >> This means all of the results have to be mapped from nodes to
>>> >> HippoBeans
>>> >> and iterated over in memory.
>>> >> This has *serious* consequences with regards to space and time
>>> >> characteristics of creating a paged result. On a larger resultset and I
>>> >> cannot imagine this is something I would want to do.
>>> >>
>>> >> With that out of the way, I would still need a way to get the total
>>> >> results. As I mentioned, debugging through the source I see that the
>>> >> query
>>> >> fired when using offset/limit is still a query for all results;
>>> >> Therefore I
>>> >> assume that you only map the subset of the total nodes found based on
>>> >> offset/limit parameters set on the query. If this is the case, wouldn't
>>> >> it
>>> >> be possible to record the total number of nodes and expose these
>>> >> through the
>>> >> queryresult? This would be ideal.
>>> >>
>>> >> Awaiting your response,
>>> >>
>>> >> Cheers
>>> >>
>>> >> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers
>>> >> <[hidden email]>
>>> >> wrote:
>>> >>>
>>> >>> Hello Rob,
>>> >>>
>>> >>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>>> >>> <[hidden email]> wrote:
>>> >>> > Hi Jeroen,
>>> >>> >
>>> >>> > If it was only that simple ;-)
>>> >>> > Your code returns the size of the limited subset of the total set
>>> >>> > paginated.
>>> >>> > So in my code example returns '10'.
>>> >>> >
>>> >>> > However, debugging shows me the xpath query executed against the
>>> >>> > repository.
>>> >>> > Executing this same query through the repository util -as I call it-
>>> >>> > I
>>> >>> > can
>>> >>> > see the the total number of results is correct.
>>> >>> >
>>> >>> > So my question remains..
>>> >>> > May no such method be provided right now, can you guys provide it?
>>> >>>
>>> >>> It is already there, only, it needs to be documented better:
>>> >>>
>>> >>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>>> >>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>>> >>> if the to the search criteria matched hundreds of documents. If you
>>> >>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>>> >>> less then without the offset.
>>> >>>
>>> >>> This limit is there to be used for performance, and suits for example
>>> >>> very well the : show last 3 agenda items on homepage.
>>> >>>
>>> >>> Now, if you need paging & only want 10 results, you do not use the
>>> >>> setLimit. (in jsr-283 i think there are again some methods added to
>>> >>> the api for this, but jackrabbit is still jsr-170).
>>> >>>
>>> >>> What you do use, is just the query without setLimit. Then you'll get
>>> >>> back a queryResult, from which you get a HippoBeanIterator. This is a
>>> >>> normal iterator, with some extensions. A very important one is :
>>> >>> skip(int skipNum)
>>> >>>
>>> >>> >From the HippoBeanIterator, you can simply iterate the beans you
>>> >>> need:
>>> >>> make sure you use skip to jump to the correct place (if current page =
>>> >>> 11 and pagesize = 20, skipNum to 220).
>>> >>>
>>> >>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>>> >>> - skipNum + pageSize
>>> >>>
>>> >>> There is a forge project example of this
>>> >>>
>>> >>> Regards Ard
>>> >>>
>>> >>> ps for those familiar to repository 1 in combination with slide, the
>>> >>> set limit now thus works differently
>>> >>>
>>> >>> >
>>> >>> > Cheers
>>> >>> >
>>> >>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>>> >>> > wrote:
>>> >>> >>
>>> >>> >> Hi Rob,
>>> >>> >>
>>> >>> >> yes that's possible. Try:
>>> >>> >>
>>> >>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>>> >>> >>  hits.getSize();
>>> >>> >>
>>> >>> >> That should be it.
>>> >>> >>
>>> >>> >> Regards,
>>> >>> >>
>>> >>> >> Jeroen
>>> >>> >>
>>> >>> >>
>>> >>> >> Rob van der Linden Vooren wrote:
>>> >>> >>>
>>> >>> >>> Hi,
>>> >>> >>>
>>> >>> >>> I'm using the query classes in order to search my content.
>>> >>> >>> I'd like to paginate my results. Assume the search for "my
>>> >>> >>> keywords"
>>> >>> >>> results in 100 hits, of which I would like to show the first 10
>>> >>> >>> results.
>>> >>> >>> In order to achieve this, suppose I'm using the following code
>>> >>> >>> snippet:
>>> >>> >>>
>>> >>> >>> HstQuery query = getQueryManager().createQuery(requestContext,
>>> >>> >>> scope,
>>> >>> >>> filterBean);
>>> >>> >>> Filter filter = query.createFilter();
>>> >>> >>> filter.addContains(".", "my keywords");
>>> >>> >>> query.setFilter(filter);
>>> >>> >>> query.setOffset(0);
>>> >>> >>> query.setLimit(10);
>>> >>> >>> HstQuery queryResult = query.execute();
>>> >>> >>>
>>> >>> >>> At this point, I get in trouble when trying to paginate my
>>> >>> >>> results.
>>> >>> >>> In particular I need the following information:
>>> >>> >>>
>>> >>> >>> - the total number of results
>>> >>> >>>
>>> >>> >>> Where to get it? I would expect to be able to do something such
>>> >>> >>> as:
>>> >>> >>>
>>> >>> >>> queryResult.getTotalResultSize()
>>> >>> >>>
>>> >>> >>> But there is no such thing; Any hints on where to find it?
>>> >>> >>>
>>> >>> >>> Cheers,
>>> >>> >>>
>>> >>> >>> --
>>> >>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> >>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>> >>> >>> General conditions apply
>>> >>> >>>
>>> >>> >>>
>>> >>> >>>
>>> >>> >>>
>>> >>> >>> ------------------------------------------------------------------------
>>> >>> >>>
>>> >>> >>> _______________________________________________
>>> >>> >>> Hippo-cms7-user mailing list and forums
>>> >>> >>> http://www.onehippo.org/cms7/support/community.html
>>> >>> >>
>>> >>> >> _______________________________________________
>>> >>> >> Hippo-cms7-user mailing list and forums
>>> >>> >> http://www.onehippo.org/cms7/support/community.html
>>> >>> >
>>> >>> >
>>> >>> >
>>> >>> > --
>>> >>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> >>> > +31(0)2-04862036
>>> >>> > | www.jteam.nl
>>> >>> > General conditions apply
>>> >>> >
>>> >>> >
>>> >>> > _______________________________________________
>>> >>> > Hippo-cms7-user mailing list and forums
>>> >>> > http://www.onehippo.org/cms7/support/community.html
>>> >>> >
>>> >>> _______________________________________________
>>> >>> Hippo-cms7-user mailing list and forums
>>> >>> http://www.onehippo.org/cms7/support/community.html
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> >> +31(0)2-04862036 | www.jteam.nl
>>> >> General conditions apply
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>> > +31(0)2-04862036
>>> > | www.jteam.nl
>>> > General conditions apply
>>> >
>>> >
>>> > _______________________________________________
>>> > Hippo-cms7-user mailing list and forums
>>> > http://www.onehippo.org/cms7/support/community.html
>>> >
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>
>>
>>
>> --
>> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
>> | www.jteam.nl
>> General conditions apply
>>
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Ard

Re: Query interface and pagination

Reply Threaded More More options
Print post
Permalink
On Thu, Jun 4, 2009 at 7:38 PM, Jasha Joachimsthal
<[hidden email]> wrote:

> 2009/6/4 Ard Schrijvers <[hidden email]>:
>> On Thu, Jun 4, 2009 at 6:12 PM, Rob van der Linden Vooren
>> <[hidden email]> wrote:
>>> Hi Ard,
>>>
>>> On the upside, you can now pretty much copy/paste the answer to my question
>>> as documentation ;-).
>>
>> I keep hoping somebody else who has knowledge about styling and such
>> would do this for me...I think we'll find this person on short notice!
>>
>> In the mean time i am, when i have some spare time, working on the
>> technical documentation explaining how the hst2 works. Stay tuned
>
> Something like http://blog.jasha.eu/2009/06/hippo-site-toolkit-query-interface-and.html
> ? :)

Great....my writing isn't 'ready as copy past documentation', but
certainly good enough to fill a blogpost. Thanks Jasha. When I get to
the search documentation, I, or somebody else, will think about your
blog :-))

Ard

>
> Jasha
>
>>
>> Ard
>>
>>>
>>> Cheers, Rob
>>>
>>>
>>> On Thu, Jun 4, 2009 at 4:12 PM, Ard Schrijvers <[hidden email]>
>>> wrote:
>>>>
>>>> On Thu, Jun 4, 2009 at 4:04 PM, Rob van der Linden Vooren
>>>> <[hidden email]> wrote:
>>>> > Hi,
>>>> >
>>>> > Unless offcourse the iterator is a proxy ...
>>>>
>>>> If I would have read this second mail before, it would have spared my
>>>> quite some time by answering yes :-(((((
>>>>
>>>>
>>>>
>>>> >
>>>> > Cheers
>>>> >
>>>> > On Thu, Jun 4, 2009 at 3:51 PM, Rob van der Linden Vooren
>>>> > <[hidden email]>
>>>> > wrote:
>>>> >>
>>>> >> Hi Ard,
>>>> >>
>>>> >> If I understand correctly, what you are saying is:
>>>> >>
>>>> >> 1. If you want to paginate, query for all results and use the skipNum()
>>>> >> method to do pagination.
>>>> >> 2. If you want to show a top list, query with limit
>>>> >>
>>>> >> This means all of the results have to be mapped from nodes to
>>>> >> HippoBeans
>>>> >> and iterated over in memory.
>>>> >> This has *serious* consequences with regards to space and time
>>>> >> characteristics of creating a paged result. On a larger resultset and I
>>>> >> cannot imagine this is something I would want to do.
>>>> >>
>>>> >> With that out of the way, I would still need a way to get the total
>>>> >> results. As I mentioned, debugging through the source I see that the
>>>> >> query
>>>> >> fired when using offset/limit is still a query for all results;
>>>> >> Therefore I
>>>> >> assume that you only map the subset of the total nodes found based on
>>>> >> offset/limit parameters set on the query. If this is the case, wouldn't
>>>> >> it
>>>> >> be possible to record the total number of nodes and expose these
>>>> >> through the
>>>> >> queryresult? This would be ideal.
>>>> >>
>>>> >> Awaiting your response,
>>>> >>
>>>> >> Cheers
>>>> >>
>>>> >> On Thu, Jun 4, 2009 at 3:18 PM, Ard Schrijvers
>>>> >> <[hidden email]>
>>>> >> wrote:
>>>> >>>
>>>> >>> Hello Rob,
>>>> >>>
>>>> >>> On Thu, Jun 4, 2009 at 3:02 PM, Rob van der Linden Vooren
>>>> >>> <[hidden email]> wrote:
>>>> >>> > Hi Jeroen,
>>>> >>> >
>>>> >>> > If it was only that simple ;-)
>>>> >>> > Your code returns the size of the limited subset of the total set
>>>> >>> > paginated.
>>>> >>> > So in my code example returns '10'.
>>>> >>> >
>>>> >>> > However, debugging shows me the xpath query executed against the
>>>> >>> > repository.
>>>> >>> > Executing this same query through the repository util -as I call it-
>>>> >>> > I
>>>> >>> > can
>>>> >>> > see the the total number of results is correct.
>>>> >>> >
>>>> >>> > So my question remains..
>>>> >>> > May no such method be provided right now, can you guys provide it?
>>>> >>>
>>>> >>> It is already there, only, it needs to be documented better:
>>>> >>>
>>>> >>> If you use setLimit(3), you will get at most 3 hits. Never more. When
>>>> >>> you ask the getSize() from the queryResult, you'll get at most 3. Even
>>>> >>> if the to the search criteria matched hundreds of documents. If you
>>>> >>> use offset(10) and no limit, you'll get for the getSize, just 10 hits
>>>> >>> less then without the offset.
>>>> >>>
>>>> >>> This limit is there to be used for performance, and suits for example
>>>> >>> very well the : show last 3 agenda items on homepage.
>>>> >>>
>>>> >>> Now, if you need paging & only want 10 results, you do not use the
>>>> >>> setLimit. (in jsr-283 i think there are again some methods added to
>>>> >>> the api for this, but jackrabbit is still jsr-170).
>>>> >>>
>>>> >>> What you do use, is just the query without setLimit. Then you'll get
>>>> >>> back a queryResult, from which you get a HippoBeanIterator. This is a
>>>> >>> normal iterator, with some extensions. A very important one is :
>>>> >>> skip(int skipNum)
>>>> >>>
>>>> >>> >From the HippoBeanIterator, you can simply iterate the beans you
>>>> >>> need:
>>>> >>> make sure you use skip to jump to the correct place (if current page =
>>>> >>> 11 and pagesize = 20, skipNum to 220).
>>>> >>>
>>>> >>> Then, you simple fill your List<HippoBean> in a for loop from skipNum
>>>> >>> - skipNum + pageSize
>>>> >>>
>>>> >>> There is a forge project example of this
>>>> >>>
>>>> >>> Regards Ard
>>>> >>>
>>>> >>> ps for those familiar to repository 1 in combination with slide, the
>>>> >>> set limit now thus works differently
>>>> >>>
>>>> >>> >
>>>> >>> > Cheers
>>>> >>> >
>>>> >>> > On Thu, Jun 4, 2009 at 2:56 PM, Jeroen Reijn <[hidden email]>
>>>> >>> > wrote:
>>>> >>> >>
>>>> >>> >> Hi Rob,
>>>> >>> >>
>>>> >>> >> yes that's possible. Try:
>>>> >>> >>
>>>> >>> >> HippoBeanIterator hits = queryResult.getHippoBeans();
>>>> >>> >>  hits.getSize();
>>>> >>> >>
>>>> >>> >> That should be it.
>>>> >>> >>
>>>> >>> >> Regards,
>>>> >>> >>
>>>> >>> >> Jeroen
>>>> >>> >>
>>>> >>> >>
>>>> >>> >> Rob van der Linden Vooren wrote:
>>>> >>> >>>
>>>> >>> >>> Hi,
>>>> >>> >>>
>>>> >>> >>> I'm using the query classes in order to search my content.
>>>> >>> >>> I'd like to paginate my results. Assume the search for "my
>>>> >>> >>> keywords"
>>>> >>> >>> results in 100 hits, of which I would like to show the first 10
>>>> >>> >>> results.
>>>> >>> >>> In order to achieve this, suppose I'm using the following code
>>>> >>> >>> snippet:
>>>> >>> >>>
>>>> >>> >>> HstQuery query = getQueryManager().createQuery(requestContext,
>>>> >>> >>> scope,
>>>> >>> >>> filterBean);
>>>> >>> >>> Filter filter = query.createFilter();
>>>> >>> >>> filter.addContains(".", "my keywords");
>>>> >>> >>> query.setFilter(filter);
>>>> >>> >>> query.setOffset(0);
>>>> >>> >>> query.setLimit(10);
>>>> >>> >>> HstQuery queryResult = query.execute();
>>>> >>> >>>
>>>> >>> >>> At this point, I get in trouble when trying to paginate my
>>>> >>> >>> results.
>>>> >>> >>> In particular I need the following information:
>>>> >>> >>>
>>>> >>> >>> - the total number of results
>>>> >>> >>>
>>>> >>> >>> Where to get it? I would expect to be able to do something such
>>>> >>> >>> as:
>>>> >>> >>>
>>>> >>> >>> queryResult.getTotalResultSize()
>>>> >>> >>>
>>>> >>> >>> But there is no such thing; Any hints on where to find it?
>>>> >>> >>>
>>>> >>> >>> Cheers,
>>>> >>> >>>
>>>> >>> >>> --
>>>> >>> >>> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>>> >>> >>> +31(0)2-04862036 | www.jteam.nl <http://www.jteam.nl>
>>>> >>> >>> General conditions apply
>>>> >>> >>>
>>>> >>> >>>
>>>> >>> >>>
>>>> >>> >>>
>>>> >>> >>> ------------------------------------------------------------------------
>>>> >>> >>>
>>>> >>> >>> _______________________________________________
>>>> >>> >>> Hippo-cms7-user mailing list and forums
>>>> >>> >>> http://www.onehippo.org/cms7/support/community.html
>>>> >>> >>
>>>> >>> >> _______________________________________________
>>>> >>> >> Hippo-cms7-user mailing list and forums
>>>> >>> >> http://www.onehippo.org/cms7/support/community.html
>>>> >>> >
>>>> >>> >
>>>> >>> >
>>>> >>> > --
>>>> >>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>>> >>> > +31(0)2-04862036
>>>> >>> > | www.jteam.nl
>>>> >>> > General conditions apply
>>>> >>> >
>>>> >>> >
>>>> >>> > _______________________________________________
>>>> >>> > Hippo-cms7-user mailing list and forums
>>>> >>> > http://www.onehippo.org/cms7/support/community.html
>>>> >>> >
>>>> >>> _______________________________________________
>>>> >>> Hippo-cms7-user mailing list and forums
>>>> >>> http://www.onehippo.org/cms7/support/community.html
>>>> >>
>>>> >>
>>>> >>
>>>> >> --
>>>> >> Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>>> >> +31(0)2-04862036 | www.jteam.nl
>>>> >> General conditions apply
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Rob van der Linden Vooren | Software Engineer | JTeam | T:
>>>> > +31(0)2-04862036
>>>> > | www.jteam.nl
>>>> > General conditions apply
>>>> >
>>>> >
>>>> > _______________________________________________
>>>> > Hippo-cms7-user mailing list and forums
>>>> > http://www.onehippo.org/cms7/support/community.html
>>>> >
>>>> _______________________________________________
>>>> Hippo-cms7-user mailing list and forums
>>>> http://www.onehippo.org/cms7/support/community.html
>>>
>>>
>>>
>>> --
>>> Rob van der Linden Vooren | Software Engineer | JTeam | T: +31(0)2-04862036
>>> | www.jteam.nl
>>> General conditions apply
>>>
>>>
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/community.html
>>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html