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.
Implements
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public sealed class SearcherManager : ReferenceManager<IndexSearcher>, IDisposable
Constructors
| Improve this Doc View SourceSearcherManager(IndexWriter, Boolean, 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. |
| System.Boolean | applyAllDeletes | If |
| SearcherFactory | searcherFactory | An optional SearcherFactory. Pass |
Exceptions
| Type | Condition |
|---|---|
| System.IO.IOException | if there is a low-level I/O error |
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 |
|---|---|
| System.IO.IOException | If there is a low-level I/O error |
Methods
| Improve this Doc View SourceDecRef(IndexSearcher)
Declaration
protected override void DecRef(IndexSearcher reference)
Parameters
| Type | Name | Description |
|---|---|---|
| IndexSearcher | reference |
Overrides
GetRefCount(IndexSearcher)
Declaration
protected override int GetRefCount(IndexSearcher reference)
Parameters
| Type | Name | Description |
|---|---|---|
| IndexSearcher | reference |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
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 |
IsSearcherCurrent()
Returns true if no changes have occured since this searcher
ie. reader was opened, otherwise false.
Declaration
public bool IsSearcherCurrent()
Returns
| Type | Description |
|---|---|
| System.Boolean |
See Also
| Improve this Doc View SourceRefreshIfNeeded(IndexSearcher)
Declaration
protected override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh)
Parameters
| Type | Name | Description |
|---|---|---|
| IndexSearcher | referenceToRefresh |
Returns
| Type | Description |
|---|---|
| IndexSearcher |
Overrides
TryIncRef(IndexSearcher)
Declaration
protected override bool TryIncRef(IndexSearcher reference)
Parameters
| Type | Name | Description |
|---|---|---|
| IndexSearcher | reference |
Returns
| Type | Description |
|---|---|
| System.Boolean |