You can always iterate over the full result set and count yourself.

The -1 in recent jackrabbit versions comes from performance
improvements, that will make searches faster because the jr search
implementation does not have to load the full result set (from
lucene). The order by "trick" works because that is a case where the
full result set has to be loaded anyway, for sorting, and hence the
count is known.

A good practice is to avoid counts as often as possible. A popular
example is Gmail, which often says things like "mails 1-50 of
hundreds" on the first page and will only count when you go onto the
next pages, ie. when the user really "seems" interested in the actual
total number of results.

Regards,
Alex

On Wed, Feb 17, 2010 at 15:14, Jacco van Weert <[email protected]> wrote:
>
> Hello Marcus,
> Yes that works, thanks... the only point is that probably this isn't
> backupped by the docs.
> So there might be a chance that in later revisions this also won't work.
> In the end I think there should be a supported way to retrieve the number of
> results.
> gr,
>   Jacco
>
>
> On Wed, Feb 17, 2010 at 2:55 PM, Marcus Park <[email protected]> wrote:
>>
>> Hi! You can get size if you use 'order by' clause in your query.
>>
>> Thanks!
>> On Feb 17, 2010, at 10:13 PM, Jacco van Weert <[email protected]>
>> wrote:
>>
>>
>> Achhhh... now I see... I did rely on the getSize() method of the
>> NodeIterator.
>> Looking through the docs and the mailinglist I see that there is no real
>> way of retrieving the number of results?
>> gr,
>>    Jacco
>>
>>
>> On Wed, Feb 17, 2010 at 10:44 AM, Jukka Zitting <[email protected]>
>> wrote:
>>>
>>> Hi,
>>>
>>> On Wed, Feb 17, 2010 at 10:18 AM, Jacco van Weert
>>> <[email protected]> wrote:
>>> > For some time I am battling with the queries in Jackrabbit v2.0.
>>> > For some reason all my query results (QueryResult .getNodes() ) are
>>> > resulting in a -1 size, I guess this indicates an error, otherwise it
>>> > should
>>> > be 0.
>>>
>>> "[...] In some implementations precise information about the number of
>>> elements may not be available. In such cases this method must return
>>> -1. [...]"
>>>
>>> http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()
>>>
>>> You'll get an exception if the query execution fails for some reason.
>>>
>>> BR,
>>>
>>> Jukka Zitting
>>
>>
>>
>> --
>> -------------------------------------
>> Jacco van Weert -- [email protected]
>> JCR Controller -- http://www.xs4all.nl/~weertj/jcr
>> JeCARS -- http://kenai.com/projects/jecars
>>
>
>
>
> --
> -------------------------------------
> Jacco van Weert -- [email protected]
> JCR Controller -- http://www.xs4all.nl/~weertj/jcr
> JeCARS -- http://kenai.com/projects/jecars
>
>



-- 
Alexander Klimetschek
[email protected]

Reply via email to