Show / Hide Table of Contents

    Class SearcherManager

    Utility class to safely share IndexSearcher instances across multiple threads, while periodically reopening. This class ensures each searcher is disposed only once all threads have finished using it.

    Use Acquire() to obtain the current searcher, and Release(G) to release it, like this:

    IndexSearcher s = manager.Acquire();
    try 
    {
        // Do searching, doc retrieval, etc. with s
    } 
    finally 
    {
        manager.Release(s);
        // Do not use s after this!
        s = null;
    }

    In addition you should periodically call MaybeRefresh(). While it's possible to call this just before running each query, this is discouraged since it penalizes the unlucky queries that do the reopen. It's better to use a separate background thread, that periodically calls MaybeRefresh(). Finally, be sure to call Dispose() once you are done.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Inheritance
    System.Object
    ReferenceManager<IndexSearcher>
    SearcherManager
    Implements
    System.IDisposable
    Inherited Members
    ReferenceManager<IndexSearcher>.Current
    ReferenceManager<IndexSearcher>.Acquire()
    ReferenceManager<IndexSearcher>.Dispose()
    ReferenceManager<IndexSearcher>.Dispose(Boolean)
    ReferenceManager<IndexSearcher>.MaybeRefresh()
    ReferenceManager<IndexSearcher>.MaybeRefreshBlocking()
    ReferenceManager<IndexSearcher>.AfterMaybeRefresh()
    ReferenceManager<IndexSearcher>.Release(IndexSearcher)
    ReferenceManager<IndexSearcher>.AddListener(ReferenceManager.IRefreshListener)
    ReferenceManager<IndexSearcher>.RemoveListener(ReferenceManager.IRefreshListener)
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class SearcherManager : ReferenceManager<IndexSearcher>, IDisposable

    Constructors

    | Improve this Doc View Source

    SearcherManager(IndexWriter, Boolean, SearcherFactory)

    Creates and returns a new SearcherManager from the given IndexWriter.

    Declaration
    public SearcherManager(IndexWriter writer, bool applyAllDeletes, SearcherFactory searcherFactory)
    Parameters
    Type Name Description
    IndexWriter writer

    The IndexWriter to open the IndexReader from.

    System.Boolean applyAllDeletes

    If true, all buffered deletes will be applied (made visible) in the IndexSearcher / DirectoryReader. If false, the deletes may or may not be applied, but remain buffered (in IndexWriter) so that they will be applied in the future. Applying deletes can be costly, so if your app can tolerate deleted documents being returned you might gain some performance by passing false. See OpenIfChanged(DirectoryReader, IndexWriter, Boolean).

    SearcherFactory searcherFactory

    An optional SearcherFactory. Pass null if you don't require the searcher to be warmed before going live or other custom behavior.

    Exceptions
    Type Condition
    System.IO.IOException

    if there is a low-level I/O error

    | Improve this Doc View Source

    SearcherManager(Directory, SearcherFactory)

    Creates and returns a new SearcherManager from the given Directory.

    Declaration
    public SearcherManager(Directory dir, SearcherFactory searcherFactory)
    Parameters
    Type Name Description
    Directory dir

    The directory to open the DirectoryReader on.

    SearcherFactory searcherFactory

    An optional SearcherFactory. Pass null if you don't require the searcher to be warmed before going live or other custom behavior.

    Exceptions
    Type Condition
    System.IO.IOException

    If there is a low-level I/O error

    Methods

    | Improve this Doc View Source

    DecRef(IndexSearcher)

    Declaration
    protected override void DecRef(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Overrides
    Lucene.Net.Search.ReferenceManager<Lucene.Net.Search.IndexSearcher>.DecRef(Lucene.Net.Search.IndexSearcher)
    | Improve this Doc View Source

    GetRefCount(IndexSearcher)

    Declaration
    protected override int GetRefCount(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Returns
    Type Description
    System.Int32
    Overrides
    Lucene.Net.Search.ReferenceManager<Lucene.Net.Search.IndexSearcher>.GetRefCount(Lucene.Net.Search.IndexSearcher)
    | Improve this Doc View Source

    GetSearcher(SearcherFactory, IndexReader)

    Expert: creates a searcher from the provided IndexReader using the provided SearcherFactory. NOTE: this decRefs incoming reader on throwing an exception.

    Declaration
    public static IndexSearcher GetSearcher(SearcherFactory searcherFactory, IndexReader reader)
    Parameters
    Type Name Description
    SearcherFactory searcherFactory
    IndexReader reader
    Returns
    Type Description
    IndexSearcher
    | Improve this Doc View Source

    IsSearcherCurrent()

    Returns true if no changes have occured since this searcher ie. reader was opened, otherwise false.

    Declaration
    public bool IsSearcherCurrent()
    Returns
    Type Description
    System.Boolean
    See Also
    IsCurrent()
    | Improve this Doc View Source

    RefreshIfNeeded(IndexSearcher)

    Declaration
    protected override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh)
    Parameters
    Type Name Description
    IndexSearcher referenceToRefresh
    Returns
    Type Description
    IndexSearcher
    Overrides
    Lucene.Net.Search.ReferenceManager<Lucene.Net.Search.IndexSearcher>.RefreshIfNeeded(Lucene.Net.Search.IndexSearcher)
    | Improve this Doc View Source

    TryIncRef(IndexSearcher)

    Declaration
    protected override bool TryIncRef(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Returns
    Type Description
    System.Boolean
    Overrides
    Lucene.Net.Search.ReferenceManager<Lucene.Net.Search.IndexSearcher>.TryIncRef(Lucene.Net.Search.IndexSearcher)

    Implements

    System.IDisposable

    Extension Methods

    ReferenceManagerExtensions.GetContext<T>(ReferenceManager<T>)
    Number.IsNumber(Object)

    See Also

    SearcherFactory
    • Improve this Doc
    • View Source
    Back to top Copyright © 2019 Licensed to the Apache Software Foundation (ASF)