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.
Note
This API is experimental and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public sealed class SearcherManager : ReferenceManager<IndexSearcher>, IDisposable
Constructors
SearcherManager(IndexWriter, bool, SearcherFactory)
Creates and returns a new SearcherManager from the given IndexWriter.
Declaration
public SearcherManager(IndexWriter writer, bool applyAllDeletes, SearcherFactory searcherFactory)
Parameters
Type | Name | Description |
---|---|---|
IndexWriter | writer | The IndexWriter to open the IndexReader from. |
bool | applyAllDeletes | If |
SearcherFactory | searcherFactory | An optional SearcherFactory. Pass |
Exceptions
Type | Condition |
---|---|
IOException | if there is a low-level I/O error |
See Also
SearcherManager(Directory, SearcherFactory)
Creates and returns a new SearcherManager from the given Directory.
Declaration
public SearcherManager(Directory dir, SearcherFactory searcherFactory)
Parameters
Type | Name | Description |
---|---|---|
Directory | dir | The directory to open the DirectoryReader on. |
SearcherFactory | searcherFactory | An optional SearcherFactory. Pass
|
Exceptions
Type | Condition |
---|---|
IOException | If there is a low-level I/O error |
See Also
Methods
DecRef(IndexSearcher)
Decrement reference counting on the given reference.
Declaration
protected override void DecRef(IndexSearcher reference)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | reference |
Overrides
Exceptions
Type | Condition |
---|---|
IOException | If reference decrement on the given resource failed. |
See Also
GetRefCount(IndexSearcher)
Returns the current reference count of the given reference.
Declaration
protected override int GetRefCount(IndexSearcher reference)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | reference |
Returns
Type | Description |
---|---|
int |
Overrides
See Also
GetSearcher(SearcherFactory, IndexReader)
Expert: creates a searcher from the provided IndexReader using the provided SearcherFactory. NOTE: this decRefs incoming reader on throwing an exception.
Declaration
public static IndexSearcher GetSearcher(SearcherFactory searcherFactory, IndexReader reader)
Parameters
Type | Name | Description |
---|---|---|
SearcherFactory | searcherFactory | |
IndexReader | reader |
Returns
Type | Description |
---|---|
IndexSearcher |
See Also
IsSearcherCurrent()
Returns true
if no changes have occured since this searcher
ie. reader was opened, otherwise false
.
Declaration
public bool IsSearcherCurrent()
Returns
Type | Description |
---|---|
bool |
See Also
RefreshIfNeeded(IndexSearcher)
Refresh the given reference if needed. Returns null
if no refresh
was needed, otherwise a new refreshed reference.
Declaration
protected override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | referenceToRefresh |
Returns
Type | Description |
---|---|
IndexSearcher |
Overrides
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | If the reference manager has been Dispose()d. |
IOException | If the refresh operation failed |
See Also
TryIncRef(IndexSearcher)
Try to increment reference counting on the given reference. Returns true
if
the operation was successful.
Declaration
protected override bool TryIncRef(IndexSearcher reference)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | reference |
Returns
Type | Description |
---|---|
bool |
Overrides
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | if the reference manager has been Dispose()d. |