
SearcherManager
- Namespace
- Rowles.LeanLucene.Search.Searcher
- Assembly
- Rowles.LeanLucene.dll
Manages the lifecycle of IndexSearcher instances, automatically refreshing when new commits are detected. Thread-safe acquire/release pattern with reference counting ensures old searchers are disposed only after all in-flight searches complete.
public sealed class SearcherManager : IDisposable
SearcherManager(MMapDirectory, SearcherManagerConfig?)
Initialises a new SearcherManager for the specified directory, opening an initial IndexSearcher and starting the background refresh loop.
ConsecutiveRefreshFailures
Number of consecutive failed refreshes since the last successful one. Reset to zero on each successful refresh.
LastRefreshError
The exception thrown by the most recent refresh attempt, or null if the most recent refresh succeeded (or none has run yet).
LastRefreshErrorAt
The UTC timestamp at which LastRefreshError was recorded, or null if no refresh has failed yet.
Acquire()
Acquires a reference to the current searcher. The caller must call Release(IndexSearcher) when done. The searcher remains valid until released.
AcquireLease()
Acquires a scoped reference to the current searcher. Disposing the returned
SearcherLease releases the reference. This is the preferred
alternative to Acquire() + Release(IndexSearcher): the lease
bypasses the ConditionalWeakTable lookup performed by Release.
Dispose()
Stops the background refresh loop and disposes the current searcher.
MaybeRefresh()
Synchronously checks for a new commit and swaps in a fresh searcher if one is found. Returns true if the searcher was refreshed.
MaybeRefreshAsync(CancellationToken)
Async variant of MaybeRefresh().
Release(IndexSearcher)
Releases a previously acquired searcher. If this was the last reference, it will be disposed.
UsingSearcher<T>(Func<IndexSearcher, T>)
Convenience method: acquires a searcher, runs the action, and releases it.
RefreshFailed
Raised when a refresh fails. The exception is also stored on LastRefreshError for callers that prefer polling.