Class SearcherLifetimeManager
Keeps track of current plus old Index
Use it like this:
SearcherLifetimeManager mgr = new SearcherLifetimeManager();
Per search-request, if it's a "new" search request, then
obtain the latest searcher you have (for example, by
using Searcher
// Record the current searcher, and save the returend
// token into user's search results (eg as a hidden
// HTML form field):
long token = mgr.Record(searcher);
When a follow-up search arrives, for example the user clicks next page, drills down/up, etc., take the token that you saved from the previous search and:
// If possible, obtain the same searcher as the last
// search:
IndexSearcher searcher = mgr.Acquire(token);
if (searcher != null)
{
// Searcher is still here
try
{
// do searching...
}
finally
{
mgr.Release(searcher);
// Do not use searcher after this!
searcher = null;
}
}
else
{
// Searcher was pruned -- notify user session timed
// out, or, pull fresh searcher again
}
Finally, in a separate thread, ideally the same thread that's periodically reopening your searchers, you should periodically prune old searchers:
mgr.Prune(new PruneByAge(600.0));
NOTE: keeping many searchers around means
you'll use more resources (open files, RAM) than a single
searcher. However, as long as you are using
Open
Inheritance
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class SearcherLifetimeManager : IDisposable
Methods
| Improve this Doc View SourceAcquire(Int64)
Retrieve a previously recorded Index
NOTE: this may return null
when the
requested searcher has already timed out. When this
happens you should notify your user that their session
timed out and that they'll have to restart their
search.
If this returns a non-null result, you must match
later call Release(Index
Declaration
public virtual IndexSearcher Acquire(long version)
Parameters
Type | Name | Description |
---|---|---|
System. |
version |
Returns
Type | Description |
---|---|
Index |
Dispose()
Close this to future searching; any searches still in
process in other threads won't be affected, and they
should still call Release(Index
NOTE: you must ensure no other threads are
calling Record(Index
Declaration
public virtual void Dispose()
Prune(SearcherLifetimeManager.IPruner)
Calls provided Searcher
NOTE: you must peridiocally call this, ideally from the same background thread that opens new searchers.
Declaration
public virtual void Prune(SearcherLifetimeManager.IPruner pruner)
Parameters
Type | Name | Description |
---|---|---|
Searcher |
pruner |
Record(IndexSearcher)
Records that you are now using this Index
This returns the
Declaration
public virtual long Record(IndexSearcher searcher)
Parameters
Type | Name | Description |
---|---|---|
Index |
searcher |
Returns
Type | Description |
---|---|
System. |
Release(IndexSearcher)
Release a searcher previously obtained from Acquire(Int64).
NOTE: it's fine to call this after Dispose().
Declaration
public virtual void Release(IndexSearcher s)
Parameters
Type | Name | Description |
---|---|---|
Index |
s |