You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Sergiy Shyrkov <my...@gmail.com> on 2010/02/18 15:12:27 UTC

Jackrabbit 2.0 QueryResult.getNodes().getSize() returning -1

Hello,

I recently noticed strange behaviour with the size of query results 
(using Jackrabbit 2.0.0).

In the following example:

Query query = ...;
NodeIterator ni = query.execute().getNodes()
if (ni.hasNext()) {
    long count = ni.getSize();
  ...
}

I always get -1 as the size of an non-empty iterator (I can perfectly 
iterate over it and get nodes).

Could you, please, help me understand what am I doing wrong?
I saw that behind the scenes the iterator is initialized lazily 
(LazyScoreNodeIteratorImpl), but even in that case I do not expect 
getSize() to return -1.

Thank you for any hint in advance!

Kind regards
Sergiy Shyrkov

Re: Jackrabbit 2.0 QueryResult.getNodes().getSize() returning -1

Posted by Sergiy Shyrkov <my...@gmail.com>.
Yes, I see it now, thank you!
We have migrated form Jackrabbit 1.x to Jackrabbit 2.x and found this 
out. We use queries not to only perform fulltext searches, aka Google, 
where it is not mandatory to know the exact count of results. That is 
why I am searching now for a (good performing) way to get the exact 
number of query results, apart from iterating over all the nodes.
I will post a question in the 
http://jackrabbit.markmail.org/message/7jzk7d6e7raimpxk?q=Queries+not+working+in+Jackrabbit+2.0 
thread to keep it in the same place.

Thanks
Sergiy

On 18.02.2010 15:36, Alexander Klimetschek wrote:
> On Thu, Feb 18, 2010 at 15:33, Sergiy Shyrkov
> <my...@gmail.com>  wrote:
>    
>> Thank you, Guo!
>> I should have searched in dev list also.
>>      
> Note that it this is explicitly mentioned also right in the javadocs
> of getSize(), for both JCR 1.0 and 2.0:
>
> http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/RangeIterator.html#getSize()
> http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()
>
> Regards,
> Alex
>
>    


Re: Jackrabbit 2.0 QueryResult.getNodes().getSize() returning -1

Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Feb 18, 2010 at 15:33, Sergiy Shyrkov
<my...@gmail.com> wrote:
> Thank you, Guo!
> I should have searched in dev list also.

Note that it this is explicitly mentioned also right in the javadocs
of getSize(), for both JCR 1.0 and 2.0:

http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/RangeIterator.html#getSize()
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Jackrabbit 2.0 QueryResult.getNodes().getSize() returning -1

Posted by Sergiy Shyrkov <my...@gmail.com>.
Thank you, Guo!
I should have searched in dev list also.

Kind regards
Sergiy

On 18.02.2010 15:18, Guo Du wrote:
> On Thu, Feb 18, 2010 at 2:12 PM, Sergiy Shyrkov
> <my...@gmail.com>  wrote:
>    
>> I always get -1 as the size of an non-empty iterator (I can perfectly
>> iterate over it and get nodes).
>>      
> The -1 discussed recently:
> http://jackrabbit.markmail.org/message/7jzk7d6e7raimpxk?q=Queries+not+working+in+Jackrabbit+2.0
>
> -Guo
>    


Re: Jackrabbit 2.0 QueryResult.getNodes().getSize() returning -1

Posted by Guo Du <mr...@gmail.com>.
On Thu, Feb 18, 2010 at 2:12 PM, Sergiy Shyrkov
<my...@gmail.com> wrote:
> I always get -1 as the size of an non-empty iterator (I can perfectly
> iterate over it and get nodes).
The -1 discussed recently:
http://jackrabbit.markmail.org/message/7jzk7d6e7raimpxk?q=Queries+not+working+in+Jackrabbit+2.0

-Guo