blob: d9060fa71b495bcca9ec3f1b044c4911616dcf8c [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Class SearcherLifetimeManager
| Apache Lucene.NET 4.8.0-beta00010 Documentation </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Class SearcherLifetimeManager
| Apache Lucene.NET 4.8.0-beta00010 Documentation ">
<meta name="generator" content="docfx 2.56.0.0">
<link rel="shortcut icon" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/favicon.ico">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.css">
<meta property="docfx:navrel" content="toc.html">
<meta property="docfx:tocrel" content="core/toc.html">
<meta property="docfx:rel" content="https://lucenenet.apache.org/docs/4.8.0-beta00009/">
</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<div id="wrapper">
<header>
<nav id="autocollapse" class="navbar ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img id="logo" class="svg" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/lucene-net-color.png" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>
<div class="subnav navbar navbar-default">
<div class="container hide-when-search">
<ul class="level0 breadcrumb">
<li>
<a href="https://lucenenet.apache.org/docs/4.8.0-beta00009/">API</a>
<span id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</span>
</li>
</ul>
</div>
</div>
</header>
<div class="container body-content">
<div id="search-results">
<div class="search-list"></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">
<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="Lucene.Net.Search.SearcherLifetimeManager">
<h1 id="Lucene_Net_Search_SearcherLifetimeManager" data-uid="Lucene.Net.Search.SearcherLifetimeManager" class="text-break">Class SearcherLifetimeManager
</h1>
<div class="markdown level0 summary"><p>Keeps track of current plus old <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>s, disposing
the old ones once they have timed out.</p>
<p>Use it like this:</p>
<pre><code> SearcherLifetimeManager mgr = new SearcherLifetimeManager();</code></pre>
<p>Per search-request, if it&apos;s a &quot;new&quot; search request, then
obtain the latest searcher you have (for example, by
using <a class="xref" href="Lucene.Net.Search.SearcherManager.html">SearcherManager</a>), and then record this
searcher:</p>
<pre><code> // Record the current searcher, and save the returend
// token into user&apos;s search results (eg as a hidden
// HTML form field):
long token = mgr.Record(searcher);</code></pre>
<p>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:</p>
<pre><code> // 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
}</code></pre>
<p>Finally, in a separate thread, ideally the same thread
that&apos;s periodically reopening your searchers, you should
periodically prune old searchers:</p>
<pre><code> mgr.Prune(new PruneByAge(600.0));</code></pre>
<p><strong>NOTE</strong>: keeping many searchers around means
you&apos;ll use more resources (open files, RAM) than a single
searcher. However, as long as you are using
<a class="xref" href="Lucene.Net.Index.DirectoryReader.html#Lucene_Net_Index_DirectoryReader_OpenIfChanged_Lucene_Net_Index_DirectoryReader_">OpenIfChanged(DirectoryReader)</a>, the searchers
will usually share almost all segments and the added resource usage
is contained. When a large merge has completed, and
you reopen, because that is a large change, the new
searcher will use higher additional RAM than other
searchers; but large merges don&apos;t complete very often and
it&apos;s unlikely you&apos;ll hit two of them in your expiration
window. Still you should budget plenty of heap in the
runtime to have a good safety margin.</p>
</div>
<div class="markdown level0 conceptual"></div>
<div class="inheritance">
<h5>Inheritance</h5>
<div class="level0"><span class="xref">System.Object</span></div>
<div class="level1"><span class="xref">SearcherLifetimeManager</span></div>
</div>
<div classs="implements">
<h5>Implements</h5>
<div><span class="xref">System.IDisposable</span></div>
</div>
<div class="inheritedMembers">
<h5>Inherited Members</h5>
<div>
<span class="xref">System.Object.Equals(System.Object)</span>
</div>
<div>
<span class="xref">System.Object.Equals(System.Object, System.Object)</span>
</div>
<div>
<span class="xref">System.Object.GetHashCode()</span>
</div>
<div>
<span class="xref">System.Object.GetType()</span>
</div>
<div>
<span class="xref">System.Object.MemberwiseClone()</span>
</div>
<div>
<span class="xref">System.Object.ReferenceEquals(System.Object, System.Object)</span>
</div>
<div>
<span class="xref">System.Object.ToString()</span>
</div>
</div>
<h6><strong>Namespace</strong>: <a class="xref" href="Lucene.Net.Search.html">Lucene.Net.Search</a></h6>
<h6><strong>Assembly</strong>: Lucene.Net.dll</h6>
<h5 id="Lucene_Net_Search_SearcherLifetimeManager_syntax">Syntax</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public class SearcherLifetimeManager : IDisposable</code></pre>
</div>
<h3 id="methods">Methods
</h3>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager_Acquire_System_Int64_.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager.Acquire(System.Int64)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/NightOwl888/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L197">View Source</a>
</span>
<a id="Lucene_Net_Search_SearcherLifetimeManager_Acquire_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Acquire*"></a>
<h4 id="Lucene_Net_Search_SearcherLifetimeManager_Acquire_System_Int64_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Acquire(System.Int64)">Acquire(Int64)</h4>
<div class="markdown level1 summary"><p>Retrieve a previously recorded <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>, if it
has not yet been closed.</p>
<p><strong>NOTE</strong>: this may return <code>null</code> when the
requested searcher has already timed out. When this
happens you should notify your user that their session
timed out and that they&apos;ll have to restart their
search.</p>
<p>If this returns a non-null result, you must match
later call <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.html#Lucene_Net_Search_SearcherLifetimeManager_Release_Lucene_Net_Search_IndexSearcher_">Release(IndexSearcher)</a> on this searcher, best
from a finally clause.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual IndexSearcher Acquire(long version)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.Int64</span></td>
<td><span class="parametername">version</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a></td>
<td></td>
</tr>
</tbody>
</table>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager_Dispose.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/NightOwl888/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L315">View Source</a>
</span>
<a id="Lucene_Net_Search_SearcherLifetimeManager_Dispose_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Dispose*"></a>
<h4 id="Lucene_Net_Search_SearcherLifetimeManager_Dispose" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Dispose">Dispose()</h4>
<div class="markdown level1 summary"><p>Close this to future searching; any searches still in
process in other threads won&apos;t be affected, and they
should still call <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.html#Lucene_Net_Search_SearcherLifetimeManager_Release_Lucene_Net_Search_IndexSearcher_">Release(IndexSearcher)</a> after they are
done.</p>
<p><p><strong>NOTE</strong>: you must ensure no other threads are
calling <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.html#Lucene_Net_Search_SearcherLifetimeManager_Record_Lucene_Net_Search_IndexSearcher_">Record(IndexSearcher)</a> while you call Dispose();
otherwise it&apos;s possible not all searcher references
will be freed.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual void Dispose()</code></pre>
</div>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager_Prune_Lucene_Net_Search_SearcherLifetimeManager_IPruner_.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager.Prune(Lucene.Net.Search.SearcherLifetimeManager.IPruner)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/NightOwl888/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L265">View Source</a>
</span>
<a id="Lucene_Net_Search_SearcherLifetimeManager_Prune_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Prune*"></a>
<h4 id="Lucene_Net_Search_SearcherLifetimeManager_Prune_Lucene_Net_Search_SearcherLifetimeManager_IPruner_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Prune(Lucene.Net.Search.SearcherLifetimeManager.IPruner)">Prune(SearcherLifetimeManager.IPruner)</h4>
<div class="markdown level1 summary"><p>Calls provided <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.IPruner.html">SearcherLifetimeManager.IPruner</a> to prune entries. The
entries are passed to the <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.IPruner.html">SearcherLifetimeManager.IPruner</a> in sorted (newest to
oldest <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>) order.</p>
<p><p><strong>NOTE</strong>: you must peridiocally call this, ideally
from the same background thread that opens new
searchers.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual void Prune(SearcherLifetimeManager.IPruner pruner)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.IPruner.html">SearcherLifetimeManager.IPruner</a></td>
<td><span class="parametername">pruner</span></td>
<td></td>
</tr>
</tbody>
</table>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager_Record_Lucene_Net_Search_IndexSearcher_.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager.Record(Lucene.Net.Search.IndexSearcher)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/NightOwl888/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L166">View Source</a>
</span>
<a id="Lucene_Net_Search_SearcherLifetimeManager_Record_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Record*"></a>
<h4 id="Lucene_Net_Search_SearcherLifetimeManager_Record_Lucene_Net_Search_IndexSearcher_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Record(Lucene.Net.Search.IndexSearcher)">Record(IndexSearcher)</h4>
<div class="markdown level1 summary"><p>Records that you are now using this <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>.
Always call this when you&apos;ve obtained a possibly new
<a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>, for example from
<a class="xref" href="Lucene.Net.Search.SearcherManager.html">SearcherManager</a>. It&apos;s fine if you already passed the
same searcher to this method before.</p>
<p>This returns the <span class="xref">System.Int64</span> token that you can later pass
to <a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.html#Lucene_Net_Search_SearcherLifetimeManager_Acquire_System_Int64_">Acquire(Int64)</a> to retrieve the same <a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a>.
You should record this <span class="xref">System.Int64</span> token in the search results
sent to your user, such that if the user performs a
follow-on action (clicks next page, drills down, etc.)
the token is returned.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual long Record(IndexSearcher searcher)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a></td>
<td><span class="parametername">searcher</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.Int64</span></td>
<td></td>
</tr>
</tbody>
</table>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager_Release_Lucene_Net_Search_IndexSearcher_.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager.Release(Lucene.Net.Search.IndexSearcher)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/NightOwl888/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L215">View Source</a>
</span>
<a id="Lucene_Net_Search_SearcherLifetimeManager_Release_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Release*"></a>
<h4 id="Lucene_Net_Search_SearcherLifetimeManager_Release_Lucene_Net_Search_IndexSearcher_" data-uid="Lucene.Net.Search.SearcherLifetimeManager.Release(Lucene.Net.Search.IndexSearcher)">Release(IndexSearcher)</h4>
<div class="markdown level1 summary"><p>Release a searcher previously obtained from
<a class="xref" href="Lucene.Net.Search.SearcherLifetimeManager.html#Lucene_Net_Search_SearcherLifetimeManager_Acquire_System_Int64_">Acquire(Int64)</a>.</p>
<p><p><strong>NOTE</strong>: it&apos;s fine to call this after Dispose().</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual void Release(IndexSearcher s)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="xref" href="Lucene.Net.Search.IndexSearcher.html">IndexSearcher</a></td>
<td><span class="parametername">s</span></td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="implements">Implements</h3>
<div>
<span class="xref">System.IDisposable</span>
</div>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/apache/lucenenet/new/docs/4.8.0-beta00010/websites/apidocs/apiSpec/new?filename=Lucene_Net_Search_SearcherLifetimeManager.md&amp;value=---%0Auid%3A%20Lucene.Net.Search.SearcherLifetimeManager%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A" class="contribution-link">Improve this Doc</a>
</li>
<li>
<a href="https://github.com/apache/lucenenet/blob/release/Lucene.Net_4_8_0_beta00010/src/Lucene.Net/Search/SearcherLifetimeManager.cs/#L102" class="contribution-link">View Source</a>
</li>
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
</nav>
</div>
</div>
</div>
</div>
<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
Copyright © 2020 Licensed to the Apache Software Foundation (ASF)
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.js"></script>
</body>
</html>