Fork me on GitHub
  • API

    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.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Inheritance
    object
    ReferenceManager<IndexSearcher>
    SearcherManager
    Implements
    IDisposable
    Inherited Members
    ReferenceManager<IndexSearcher>.Acquire()
    ReferenceManager<IndexSearcher>.Dispose()
    ReferenceManager<IndexSearcher>.MaybeRefresh()
    ReferenceManager<IndexSearcher>.MaybeRefreshBlocking()
    ReferenceManager<IndexSearcher>.Release(IndexSearcher)
    ReferenceManager<IndexSearcher>.AddListener(ReferenceManager.IRefreshListener)
    ReferenceManager<IndexSearcher>.RemoveListener(ReferenceManager.IRefreshListener)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class SearcherManager : ReferenceManager<IndexSearcher>, IDisposable

    Constructors

    SearcherManager(IndexWriter, bool, 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.

    bool 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, bool).

    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
    IOException

    if there is a low-level I/O error

    See Also
    SearcherFactory

    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
    IOException

    If there is a low-level I/O error

    See Also
    SearcherFactory

    Methods

    DecRef(IndexSearcher)

    Decrement reference counting on the given reference.

    Declaration
    protected override void DecRef(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Overrides
    ReferenceManager<IndexSearcher>.DecRef(IndexSearcher)
    Exceptions
    Type Condition
    IOException

    If reference decrement on the given resource failed.

    See Also
    SearcherFactory

    GetRefCount(IndexSearcher)

    Returns the current reference count of the given reference.

    Declaration
    protected override int GetRefCount(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Returns
    Type Description
    int
    Overrides
    ReferenceManager<IndexSearcher>.GetRefCount(IndexSearcher)
    See Also
    SearcherFactory

    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
    See Also
    SearcherFactory

    IsSearcherCurrent()

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

    Declaration
    public bool IsSearcherCurrent()
    Returns
    Type Description
    bool
    See Also
    IsCurrent()

    RefreshIfNeeded(IndexSearcher)

    Refresh the given reference if needed. Returns null if no refresh was needed, otherwise a new refreshed reference.

    Declaration
    protected override IndexSearcher RefreshIfNeeded(IndexSearcher referenceToRefresh)
    Parameters
    Type Name Description
    IndexSearcher referenceToRefresh
    Returns
    Type Description
    IndexSearcher
    Overrides
    ReferenceManager<IndexSearcher>.RefreshIfNeeded(IndexSearcher)
    Exceptions
    Type Condition
    ObjectDisposedException

    If the reference manager has been Dispose()d.

    IOException

    If the refresh operation failed

    See Also
    SearcherFactory

    TryIncRef(IndexSearcher)

    Try to increment reference counting on the given reference. Returns true if the operation was successful.

    Declaration
    protected override bool TryIncRef(IndexSearcher reference)
    Parameters
    Type Name Description
    IndexSearcher reference
    Returns
    Type Description
    bool
    Overrides
    ReferenceManager<IndexSearcher>.TryIncRef(IndexSearcher)
    Exceptions
    Type Condition
    ObjectDisposedException

    if the reference manager has been Dispose()d.

    See Also
    SearcherFactory

    Implements

    IDisposable

    Extension Methods

    ReferenceManagerExtensions.GetContext<T>(ReferenceManager<T>)

    See Also

    SearcherFactory
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.