Class SearcherManager
- Namespace
- TantivyDotNet
- Assembly
- TantivyDotNet.dll
Shares one Searcher across requests and replaces it when the index changes, so requests don't each open a snapshot. Leases keep the searcher they got alive until disposed, even after it's replaced. Created by CreateSearcherManager(SearcherManagerOptions?).
public sealed class SearcherManager : IDisposable
- Inheritance
-
SearcherManager
- Implements
- Inherited Members
Examples
using var manager = index.CreateSearcherManager(new SearcherManagerOptions { RefreshOnCommit = true });
// per request:
using var lease = manager.Acquire();
var hits = lease.Searcher.Search("body:mice");
Remarks
Thread-safe. Acquire() is cheap and lock-free unless it swaps in a new searcher. Disposing the manager doesn't invalidate leases already handed out.
Methods
- Acquire()
Returns a lease on the current searcher. Dispose the lease when the request is done; the searcher stays valid until then, even if it's replaced meanwhile.
- Dispose()
Releases the manager's reference to the current searcher. Leases already handed out stay usable until disposed. Safe to call more than once.
- Refresh()
Reloads the latest commit and, if the index changed, replaces the current searcher with a new (warmed) one. Blocks while another refresh is running.