SearcherManager
Utility class to safely share IndexSearcher instances across multiple threads, while periodically reopening. This class ensures each searcher is closed only once all threads have finished using it.
Use [acquire] to obtain the current searcher, and [release] to release it, like this:
IndexSearcher s = manager.acquire();
try {
// Do searching, doc retrieval, etc. with s
} finally {
manager.release(s);
}
// Do not use s after this!
s = null;
In addition you should periodically call [maybeRefresh]. While it's possible to call this just before running each query, this is discouraged since it penalizes the unlucky queries that need to refresh. It's better to use a separate background thread, that periodically calls [maybeRefresh]. Finally, be sure to call [close] once you are done.
See also
Constructors
Creates and returns a new SearcherManager from the given IndexWriter.
Expert: creates and returns a new SearcherManager from the given IndexWriter, controlling whether past deletions should be applied.
Creates and returns a new SearcherManager from the given Directory.
Creates and returns a new SearcherManager from an existing DirectoryReader. Note that this steals the incoming reference.
Functions
Obtain the current reference. You must match every call to acquire with one call to release; it's best to do so in a finally clause, and set the reference to null to prevent accidental usage after it has been released.
Adds a listener, to be notified when a reference is refreshed/swapped.
Closes this ReferenceManager to prevent future acquire acquiring. A reference manager should be closed if the reference to the managed resource should be disposed or the application using the ReferenceManager is shutting down. The managed resource might not be released immediately, if the ReferenceManager user is holding on to a previously acquire acquired reference. The resource will be released once when the last reference is release released. Those references can still be used as if the manager was still active.
Returns true if no changes have occurred since this searcher ie. reader was opened, otherwise false.
You must call this (or maybeRefreshBlocking), periodically, if you want that will return refreshed instances.
You must call this (or maybeRefresh), periodically, if you want that will return refreshed instances.
Release the reference previously obtained via acquire.
Removes a listener added by addListener.