lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Rhoden <>
Subject Re: Wrapping IndexSearcher so that it is safe?
Date Thu, 12 Nov 2009 21:44:13 GMT

On 12/11/2009, at 8:42 PM, Michael McCandless wrote:

> 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

After staring it it a bit longer, it mostly makes sense to me now, the  
example for book
was only hard to read because I don't understand completely what both
IndexWriter.IndexReaderWarmer() and searcher.getIndexReader().decRef()
are supposed to do. (Which I assume can be learnt from the book)

> 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.

To test I understand this correctly, the index reader getting closed  
is achieved by the release() method calling  

>> 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.
> 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
> 0?

In my version, the "SafeIndexSearcher" is a static variable, the retain
count starts at 0. Being at zero simply indicates the object is not  
used and can safely be closed.

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

Another thread runs in the background and handles deciding when to do
an index rebuild, at which point it
1) swaps in a new "SafeIndexSearcher"
2) calls close on the old "SafeIndexSearcher" (which will safely close  
once the retain count=0)


Information Technology Services,
The University of Melbourne

Phone: +61 3 8344 2884
Mobile: +61 4 1095 7575

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

View raw message