You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by hsp_ <pi...@ibest.com.br> on 2008/08/07 22:30:19 UTC
Query result with offset/limit
jackrabbit version is 1.4 (jackrabbit-core - 1.4.5).
I would to know if there is a workaround for the situation I will explain:
I use searches with result limit and offset but it is working some wrong for
my case.
Lets suppose the total of nodes that will return with the search:
NAME GRANTACCESS OFFSET
node1 true 0
node2 false 1
node3 true 2
node4 true 3
node5 false 4
My page must have 2 records, so first I do a count for the search and get
size of 3 records (after filtered by my security class invoked automatically
by jackrabbit), so I have 2 pages to show to the user. The first page must
return 2 records, of course, and the second must return 1 record.
In the first search I do set:
QueryImpl.setLimit(2);
QueryImp.setOffset(0);
So, I get the nodes 1 and 3, thats correct.
In the second same search (for second page), I do set:
QueryImpl.setLimit(2);
QueryImp.setOffset(2);
This way I pretend to get two records, starting from the record nro 3, which
would be only the node4.
But, the result I got is node3 (again) and node4, because the offset worked
not according to the grantacess (provided by the security class), but
according to the sequence of the raw result.
Is there some way to my application handle this offset to start in the
correct position (counting only the granted nodes and not all of them)? Or
maybe is this an issue?
Hope this make sense for you.
Thanks.
Helio.
--
View this message in context: http://www.nabble.com/Query-result-with-offset-limit-tp18879020p18879020.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
RE: Query result with offset/limit
Posted by Ard Schrijvers <a....@onehippo.com>.
> Marcel Reutegger wrote:
> Hi Helio,
>
> I'd say this is a bug. Can you please create a jira issue? thank you.
I am curious about a proper (performant) solution for it: AFAICS, the
only way to currently fix it, is to change the offset to an offset + the
invalid counter so far. Below, in QueryResultImpl it seems to account
for 'invalid' in start, but I think 'invalid' always starts at 0, even
if the offset is not 0. This is obviously the problem. OTOH, the
performance might drop quite a bit because it means you have to start
always with the first lucene hit, to know the 'real' (combined with
authorisation) offset
org.apache.jackrabbit.core.query.lucene.QueryResultImpl
int start = resultNodes.size() + invalid + (int)offset;
int max = Math.min(result.length(), numResults);
for (int i = start; i < max && resultNodes.size() <
maxResultSize; i++) {
NodeId id =
NodeId.valueOf(result.doc(i).get(FieldNames.UUID));
// check access
try {
if (accessMgr.isGranted(id, AccessManager.READ)) {
resultNodes.add(new ScoreNode(id,
result.score(i)));
} else {
invalid++;
}
} catch (ItemNotFoundException e) {
// has been deleted meanwhile
invalid++;
}
}
-Ard
>
> regards
> marcel
>
> hsp_ wrote:
> > jackrabbit version is 1.4 (jackrabbit-core - 1.4.5).
> > I would to know if there is a workaround for the situation
> I will explain:
> > I use searches with result limit and offset but it is working some
> > wrong for my case.
> > Lets suppose the total of nodes that will return with the search:
> >
> > NAME GRANTACCESS OFFSET
> > node1 true 0
> > node2 false 1
> > node3 true 2
> > node4 true 3
> > node5 false 4
> >
> > My page must have 2 records, so first I do a count for the
> search and
> > get size of 3 records (after filtered by my security class invoked
> > automatically by jackrabbit), so I have 2 pages to show to
> the user.
> > The first page must return 2 records, of course, and the
> second must return 1 record.
> >
> > In the first search I do set:
> > QueryImpl.setLimit(2);
> > QueryImp.setOffset(0);
> >
> > So, I get the nodes 1 and 3, thats correct.
> >
> > In the second same search (for second page), I do set:
> > QueryImpl.setLimit(2);
> > QueryImp.setOffset(2);
> > This way I pretend to get two records, starting from the
> record nro 3,
> > which would be only the node4.
> > But, the result I got is node3 (again) and node4, because
> the offset
> > worked not according to the grantacess (provided by the security
> > class), but according to the sequence of the raw result.
> >
> > Is there some way to my application handle this offset to
> start in the
> > correct position (counting only the granted nodes and not all of
> > them)? Or maybe is this an issue?
> >
> > Hope this make sense for you.
> >
> > Thanks.
> > Helio.
>
>
Re: Query result with offset/limit
Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Helio,
I'd say this is a bug. Can you please create a jira issue? thank you.
regards
marcel
hsp_ wrote:
> jackrabbit version is 1.4 (jackrabbit-core - 1.4.5).
> I would to know if there is a workaround for the situation I will explain:
> I use searches with result limit and offset but it is working some wrong for
> my case.
> Lets suppose the total of nodes that will return with the search:
>
> NAME GRANTACCESS OFFSET
> node1 true 0
> node2 false 1
> node3 true 2
> node4 true 3
> node5 false 4
>
> My page must have 2 records, so first I do a count for the search and get
> size of 3 records (after filtered by my security class invoked automatically
> by jackrabbit), so I have 2 pages to show to the user. The first page must
> return 2 records, of course, and the second must return 1 record.
>
> In the first search I do set:
> QueryImpl.setLimit(2);
> QueryImp.setOffset(0);
>
> So, I get the nodes 1 and 3, thats correct.
>
> In the second same search (for second page), I do set:
> QueryImpl.setLimit(2);
> QueryImp.setOffset(2);
> This way I pretend to get two records, starting from the record nro 3, which
> would be only the node4.
> But, the result I got is node3 (again) and node4, because the offset worked
> not according to the grantacess (provided by the security class), but
> according to the sequence of the raw result.
>
> Is there some way to my application handle this offset to start in the
> correct position (counting only the granted nodes and not all of them)? Or
> maybe is this an issue?
>
> Hope this make sense for you.
>
> Thanks.
> Helio.
RE: Query result with offset/limit
Posted by Ard Schrijvers <a....@onehippo.com>.
Hello,
>
> Hi, I am very glad with your help, thanks.
> I appreciate your suggestion by anticipation of the user
> grants to do a search more fine tuned.
> I will think about it, my model of security has a structure
> of nodes that contains links to the users and their level of
> permission over the parent of the structure, so I must to do
> a search that retry all the nodes, or at least the beginning
> of the nodes where the user can at least read, and add this
> filter to the expression being searched, maybe.
You could do that, though you have to realize that when combining the
search with path info, you're queries can become quite a bit slower (at
least, when you have to deal with lots of nodes). Then, you could chose
to index path info as well, but this disables the lightweight move
functionality from jackrabbit. There are some trade-offs.
> And about the workaround the "real" offset for that user in
> the search, I think I will do the search for the first page
> with offset=0 and limit=myPageLimit and the others pages with
> offset=o and limit=myPageLimit*pageNumber and filter the
> nodes in early pages by my application. I think this is the
> best I can do at this time about it.
Yes, I think options are currently limited, and IMHO, isn't accounted
for in the specification: the jsr-283 has come up with the limit and
offset, but....what use if you do not have the original hitposition is
an offset.
You might want to bring this up on the dev list if you want,
-Ard
>
> Thanks by your help, any other would be very appreciate.
> --
> View this message in context:
> http://www.nabble.com/Query-result-with-offset-limit-tp1887902
> 0p18883342.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>
RE: Query result with offset/limit
Posted by hsp_ <pi...@ibest.com.br>.
Hi, I am very glad with your help, thanks.
I appreciate your suggestion by anticipation of the user grants to do a
search more fine tuned.
I will think about it, my model of security has a structure of nodes that
contains links to the users and their level of permission over the parent of
the structure, so I must to do a search that retry all the nodes, or at
least the beginning of the nodes where the user can at least read, and add
this filter to the expression being searched, maybe.
And about the workaround the "real" offset for that user in the search, I
think I will do the search for the first page with offset=0 and
limit=myPageLimit and the others pages with offset=o and
limit=myPageLimit*pageNumber and filter the nodes in early pages by my
application. I think this is the best I can do at this time about it.
Thanks by your help, any other would be very appreciate.
--
View this message in context: http://www.nabble.com/Query-result-with-offset-limit-tp18879020p18883342.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
RE: Query result with offset/limit
Posted by Ard Schrijvers <a....@onehippo.com>.
Hello,
>
> In the second same search (for second page), I do set:
> QueryImpl.setLimit(2);
> QueryImp.setOffset(2);
> This way I pretend to get two records, starting from the
> record nro 3, which would be only the node4.
> But, the result I got is node3 (again) and node4, because the
> offset worked not according to the grantacess (provided by
> the security class), but according to the sequence of the raw result.
I do understand your issue. It would be nice to somehow know from each
result node what its offset was. OTOH, this offset might only be
temporarily valid, because while paging to the next page, nodes might
have been added/removed. Because you are just getting an iterator over
search results, you won't be able to add information about the offset
(in other words, what was the nodes hitposition in the lucene search).
I think it is really valuable information, which currently isn't
accessible. AFAIK, this is still not available in the jsr-283.
So, bottom line, I am not really sure how to solve it in your
case(smart, without getting *all* the authorized results). You will also
hit this problem when you want to display the number of pages, because
you can only know this number *after* you authorized every hit. Also,
your concept might be a huge bottleneck for users having very few
permissions to see nodes: if you have to grant thousands of nodes to
find for example 10 granted ones, you'll get problems.
Unless....you make sure that the lucene query gets combined with an
authorisation query such that almost every hit you get is an authorised
hit as well. This is not trivial, but certainly not impossible, since we
did it :-)...but don't expect to have something like it within a couple
of hours, it is not really trivial
Ard
>
> Is there some way to my application handle this offset to
> start in the correct position (counting only the granted
> nodes and not all of them)? Or maybe is this an issue?
>
> Hope this make sense for you.
>
> Thanks.
> Helio.
> --
> View this message in context:
> http://www.nabble.com/Query-result-with-offset-limit-tp1887902
> 0p18879020.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>