Table of Contents

Public classSealed 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

Public constructor SearcherManager(MMapDirectory, SearcherManagerConfig?)

Initialises a new SearcherManager for the specified directory, opening an initial IndexSearcher and starting the background refresh loop.

Public property ConsecutiveRefreshFailures

Number of consecutive failed refreshes since the last successful one. Reset to zero on each successful refresh.

Public property LastRefreshError

The exception thrown by the most recent refresh attempt, or null if the most recent refresh succeeded (or none has run yet).

Public property LastRefreshErrorAt

The UTC timestamp at which LastRefreshError was recorded, or null if no refresh has failed yet.

Public method Acquire()

Acquires a reference to the current searcher. The caller must call Release(IndexSearcher) when done. The searcher remains valid until released.

Public method 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.

Public method Dispose()

Stops the background refresh loop and disposes the current searcher.

Public method MaybeRefresh()

Synchronously checks for a new commit and swaps in a fresh searcher if one is found. Returns true if the searcher was refreshed.

Public method MaybeRefreshAsync(CancellationToken)

Async variant of MaybeRefresh().

Public method Release(IndexSearcher)

Releases a previously acquired searcher. If this was the last reference, it will be disposed.

Public method UsingSearcher<T>(Func<IndexSearcher, T>)

Convenience method: acquires a searcher, runs the action, and releases it.

Public event RefreshFailed

Raised when a refresh fails. The exception is also stored on LastRefreshError for callers that prefer polling.