You can use SearcherLifetimeManager to keep track of specific IndexSearcher 
instances - see Mike’s blog at 
http://blog.mikemccandless.com/2011/11/searcherlifetimemanager-prevents-broken.html
 
<http://blog.mikemccandless.com/2011/11/searcherlifetimemanager-prevents-broken.html>

Alan Woodward
www.flax.co.uk


> On 17 Nov 2017, at 08:30, ivan cruces <ivan.cru...@object-matrix.com> wrote:
> 
> Hi,
> 
> I have implemented pagination with Lucene using the searchAfter method
> provided by IndexSearcher. In every call, I pass the last ScoreDoc returned
> in the previous page.
> 
> The problem is that sometimes, the index gets updated between page and page
> and occasionally I am getting this exception:
> 
> java.lang.IllegalArgumentException: after.doc exceeds the number of
> documents in the reader: after.doc=337 limit=337
>    at
> org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:434)
> 
> I understand that Lucene changes the docs ids every now and then (segment
> merges, etc.) and I guess that is why that exception is happening as
> searchAfter relies on those docs ids.
> 
> How could I improve this pagination mechanism to avoid this exception? Is
> there any better way to implement pagination with Lucene?
> 
> 
> Thanks,
> 
> Iván.

Reply via email to