Class SearcherManager
Utility class to safely share IndexSearcher instances across multiple threads, while periodically reopening. This class ensures each searcher is disposed only once all threads have finished using it.
Use Acquire() to obtain the current searcher, and Release(G) 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 do the reopen. It's better to use a separate background thread, that periodically calls MaybeRefresh(). Finally, be sure to call Dispose() once you are done.
@lucene.experimental
Inherited Members
Assembly: DistributedLucene.Net.dll
Syntax
public sealed class SearcherManager : ReferenceManager<IndexSearcher>
Constructors
Name | Description |
---|---|
SearcherManager(IndexWriter, Boolean, SearcherFactory) | Creates and returns a new SearcherManager from the given IndexWriter. |
SearcherManager(Directory, SearcherFactory) | Creates and returns a new SearcherManager from the given Directory. |
Methods
Name | Description |
---|---|
DecRef(IndexSearcher) | |
GetRefCount(IndexSearcher) | |
GetSearcher(SearcherFactory, IndexReader) | Expert: creates a searcher from the provided IndexReader using the provided SearcherFactory. NOTE: this decRefs incoming reader on throwing an exception. |
IsSearcherCurrent() | Returns |
RefreshIfNeeded(IndexSearcher) | |
TryIncRef(IndexSearcher) |