You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Torgeir Veimo <to...@gmail.com> on 2013/10/25 05:07:00 UTC

query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

I tried upgrading from Jackrabbit 2.6.1 to 2.6.3, and now one of my
queries return size of -1, even when sorting by @jcr:score.

If I add an additional parameter, then the qurey suddenly return a
proper size value, as shown in this log output;

05:04:25,468 TRACE jcr.JcrAssetRepository.findAssets(), l: 655: using
queryString: /jcr:root//content//*/element(*,ka:asset)[@ka:assetType =
'company' ] order by @jcr:score

05:04:25,605 TRACE jcr.JcrAssetRepository.toAssets(), l: 714: loading:
100, totalCount: -1 assets took -131ms

05:04:13,451 TRACE jcr.JcrAssetRepository.findAssets(), l: 655: using
queryString: /jcr:root//content//*/element(*,ka:asset)[@ka:assetType =
'company'  and jcr:contains(., '*test*') ] order by @jcr:score

05:04:13,520 TRACE jcr.JcrAssetRepository.toAssets(), l: 714: loading:
5, totalCount: 5 assets took -8ms

Is there any other way than adding order by @jcr:score to ensure the
total count is returned in version 2.6.2+ ? I'd assume this might
caused by JCR-3402?

(I only see this on my production server, not on my test or staging
server, so it's hard to create a test case, or isolate the problem.)

-- 
-Tor

Re: query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

Posted by Ard Schrijvers <a....@onehippo.com>.
Hey Jukka,

On Tue, Oct 29, 2013 at 4:07 AM, Jukka Zitting <ju...@gmail.com> wrote:
> Hi,
>
> On Mon, Oct 28, 2013 at 4:07 AM, Ard Schrijvers
> <a....@onehippo.com> wrote:
>> IIRC, the #getSize() method worked a bit different Jukka.
>
> IIUC Torgeir was referring to the getTotalSize() method which is

Yes he was. I am sorry about the noice : for the getTotalSize method I
fully agree with your reasoning

> designed to return the total number of results that would have been
> returned if the query had no limit on it. See JCR-1073/JCR-3474.
>
>> (and since we integrated authorization into the queries we have cheap
>> correct total counts)
>
> Nice! :-)

Of course it was only possible if we put constraints on our
authorization model  : It is based on properties of nodes solely to be
able to efficiently translate it to lucene queries. See [1] in case
you're interested

>
>> Any way, imo it has always been quite confusing, but changing the
>> confusing behavior in a micro version doesn't help.
>
> This was a bit of a borderline case (see comments in JCR-3402), and it
> is indeed debatable whether it was a right call to include the change
> in a patch release. The fact that the change plugged a potential
> security issue weighed in my decision to include it.
>
> If the change is causing trouble, let's file a followup issue and see
> what should be done to make the behavior more backwards-compatible
> without compromising security.

It is not causing trouble, as I overlooked the getTotalSize method and
thought it was about getSize. Thanks for your feedback Jukka

Regards Ard

[1] http://www.onehippo.com/en/resources/blogs/2013/01/cms-7.8-nailed-down-authorization-combined-with-searches.html

>
> BR,
>
> Jukka Zitting



-- 
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

Re: query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Mon, Oct 28, 2013 at 4:07 AM, Ard Schrijvers
<a....@onehippo.com> wrote:
> IIRC, the #getSize() method worked a bit different Jukka.

IIUC Torgeir was referring to the getTotalSize() method which is
designed to return the total number of results that would have been
returned if the query had no limit on it. See JCR-1073/JCR-3474.

> (and since we integrated authorization into the queries we have cheap
> correct total counts)

Nice! :-)

> Any way, imo it has always been quite confusing, but changing the
> confusing behavior in a micro version doesn't help.

This was a bit of a borderline case (see comments in JCR-3402), and it
is indeed debatable whether it was a right call to include the change
in a patch release. The fact that the change plugged a potential
security issue weighed in my decision to include it.

If the change is causing trouble, let's file a followup issue and see
what should be done to make the behavior more backwards-compatible
without compromising security.

BR,

Jukka Zitting

Re: query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

Posted by Ard Schrijvers <a....@onehippo.com>.
On Sat, Oct 26, 2013 at 10:44 PM, Jukka Zitting <ju...@gmail.com> wrote:
> Hi,
>
> On Fri, Oct 25, 2013 at 12:24 AM, Torgeir Veimo <to...@gmail.com> wrote:
>> Furthermore it seems it happens when query limit <= result size. If I
>> set limit to one higher than the size of the result set, it correctly
>> gives the correct size.
>
> The reason for this behavior is that when you set the limit on the
> query Jackrabbit will stop counting when the limit is reached, and
> thus it won't know what the total number of results without the limit
> would be. The reason why it worked before JCR-3402 is that we used a
> guess based on the raw number of Lucene matches without considering

IIRC, the #getSize() method worked a bit different Jukka. #getSize()
on queries *with* an order by clause *and* a limit would at most give
'limit' as the size. Even if there where, say, 1.000 hits, the
#getSize() used to return only 10 in case a limit of 10 was set. For
this reason, through Hippo Repository, we also expose a 'raw'
(unauthorized) total size, which is just the result size from Lucene
(and since we integrated authorization into the queries we have cheap
correct total counts)

Any way, imo it has always been quite confusing, but changing the
confusing behavior in a micro version doesn't help. I saw the JCR-3402
some time ago. I expect the Cédric Damioli in his environment did not
use a limit on queries *and* had a default resultFetchSize of Integer
max value. Hence, under his circumstances, it might have seem like a
good improvement. OTOH, I haev to admit I am a bit second guessing as
I did not investigate it well enough

Regards Ard

> things like read access controls, which is a potential security issue
> as it could result in read-protected information leaking through the
> query system.
>
> BR,
>
> Jukka Zitting



-- 
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

Re: query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Fri, Oct 25, 2013 at 12:24 AM, Torgeir Veimo <to...@gmail.com> wrote:
> Furthermore it seems it happens when query limit <= result size. If I
> set limit to one higher than the size of the result set, it correctly
> gives the correct size.

The reason for this behavior is that when you set the limit on the
query Jackrabbit will stop counting when the limit is reached, and
thus it won't know what the total number of results without the limit
would be. The reason why it worked before JCR-3402 is that we used a
guess based on the raw number of Lucene matches without considering
things like read access controls, which is a potential security issue
as it could result in read-protected information leaking through the
query system.

BR,

Jukka Zitting

Re: query using "order by @jcr:score" returns size == -1 after upgrading 2.6.1 -> 2.6.3

Posted by Torgeir Veimo <to...@gmail.com>.
Furthermore it seems it happens when query limit <= result size. If I
set limit to one higher than the size of the result set, it correctly
gives the correct size.


On 25 October 2013 13:07, Torgeir Veimo <to...@gmail.com> wrote:
> I tried upgrading from Jackrabbit 2.6.1 to 2.6.3, and now one of my
> queries return size of -1, even when sorting by @jcr:score.
>
> If I add an additional parameter, then the qurey suddenly return a
> proper size value, as shown in this log output;
>
> 05:04:25,468 TRACE jcr.JcrAssetRepository.findAssets(), l: 655: using
> queryString: /jcr:root//content//*/element(*,ka:asset)[@ka:assetType =
> 'company' ] order by @jcr:score
>
> 05:04:25,605 TRACE jcr.JcrAssetRepository.toAssets(), l: 714: loading:
> 100, totalCount: -1 assets took -131ms
>
> 05:04:13,451 TRACE jcr.JcrAssetRepository.findAssets(), l: 655: using
> queryString: /jcr:root//content//*/element(*,ka:asset)[@ka:assetType =
> 'company'  and jcr:contains(., '*test*') ] order by @jcr:score
>
> 05:04:13,520 TRACE jcr.JcrAssetRepository.toAssets(), l: 714: loading:
> 5, totalCount: 5 assets took -8ms
>
> Is there any other way than adding order by @jcr:score to ensure the
> total count is returned in version 2.6.2+ ? I'd assume this might
> caused by JCR-3402?
>
> (I only see this on my production server, not on my test or staging
> server, so it's hard to create a test case, or isolate the problem.)
>
> --
> -Tor



-- 
-Tor