lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volodymyr Bychkoviak <>
Subject Re: Renewing IndexSearcher on index change.
Date Tue, 04 Oct 2005 15:35:21 GMT
Hi Olivier!

In my code i'm using following IndexSearcher extention:

public class IndexSearcherWrapper extends IndexSearcher {

  private int referenceCount;

  private final IndexReader indexReader;

  public IndexSearcherWrapper(IndexReader indexReader) {
    this.indexReader = indexReader;
    this.referenceCount = 1;

  public IndexSearcher getReference() {
    return this;

  public void close() throws IOException {
    if (referenceCount <= 0) {


in the code obtaining IndexSearcher I do call getReference() method and 
use indexSearcher as usual (search & close);
also referenceCount initially is set to 1 to prevent underlying 
indexReader being closed after first call of close() method.

when opening new IndexSearcher (after index change) I do call close() 
method one more time ensuring this IndexSearcher will be closed as soon 
as last thread closes this IndexSearcher.

and about second question:
while changing index all open IndexReaders(and IndexSearchers) don't 
"see" changes until reopening.

Olivier Jaquemet wrote:

> Hi all,
> As I read it on LIA, and as it has already been said on the mailing 
> list multiple times, you only need one IndexSearcher for all your 
> thread, and when your index change, you just need to create a new one 
> to reflect changes.
> Otis said in this post you could replaced old searcher and let it 
> being collected by the GC.

> Note that my question is maybe more java related than anything else, 
> but, anyway...
> In the source code of IndexSearcher (and all searchers), I could not 
> find any finalize method that closes the searcher, how can you be sure 
> you old searcher is going to be closed? am I missing something? Is 
> there still a step I need to do in order to close the searcher 
> properly ? Do I need to create a facade to the searcher, keep my own 
> reference of uses and call a close in a finalize method?
> Thanks in advance for your answers :)
> Olivier
> PS: Another small question while I'm there, if a long indexation of a 
> lot Documents occurs, can the old searcher still be used for some time 
> while the indexation takes place, without problems? Cause I encoutered 
> an ArrayOutOfBoundException under some scorer class, unfortunately I 
> did not kept the trace.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Volodymyr Bychkoviak

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message