lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <>
Subject Re: Wrapping IndexSearcher so that it is safe?
Date Thu, 12 Nov 2009 09:42:09 GMT
On Wed, Nov 11, 2009 at 7:33 PM, Jacob Rhoden <> wrote:
> The source code for SearcherManager is even downloadable for free:
> The example source code does some things that is beyond my level of
> understanding
> of lucene. ie:
> 1) To me it looks like an IndexSearcher never gets closed.

It's true that IndexSearcher isn't closed, but it turns out (for now,
at least), it's not necessary to close IndexSearcher if you had passed
it an already open IndexReader.

> 2) I don't understand what happens if the indexreader is reopened while a
> thread
>    in the middle of a search using an indexsearcher.

Any already in-flight searches will continue to use the old
IndexSearcher, while new ones use the new IndexSearcher.  Once all
in-flight searches are done against the old IndexSearcher, its
underlying IndexReader is closed.

> So I am going for something a bit simpler:
> If a thread wants to use the "SafeIndexSearcher", it first calls retain()
> and then calls
> release() when its done.
> If a thread wants to close the "SafeIndexSearcher" , the close is deferred
> until all threads
> have called release():

I think this will work, but you need a central place that has called
retain() and is holding onto the searcher, until it's time to reopen
right?  Either that, or your retainCount begins life at 1 instead of

Also, how will you handle reopening (if that's needed in your app)?


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

View raw message