lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
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 <jrhoden@unimelb.edu.au> wrote:
> The source code for SearcherManager is even downloadable for free:
>   http://www.manning.com/hatcher3/LIAsourcecode.zip
>
> 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
0?

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

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message