Show / Hide Table of Contents

    Class IndexSearcher

    Implements search over a single IndexReader.

    Applications usually need only call the inherited Search(Query, Int32) or Search(Query, Filter, Int32) methods. For performance reasons, if your index is unchanging, you should share a single IndexSearcher instance across multiple searches instead of creating a new one per-search. If your index has changed and you wish to see the changes reflected in searching, you should use OpenIfChanged(DirectoryReader) to obtain a new reader and then create a new IndexSearcher from that. Also, for low-latency turnaround it's best to use a near-real-time reader (Open(IndexWriter, Boolean)). Once you have a new IndexReader, it's relatively cheap to create a new IndexSearcher from it.

    NOTE: IndexSearcher instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexSearcher instance; use your own (non-Lucene) objects instead.

    Inheritance
    System.Object
    IndexSearcher
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public class IndexSearcher : object

    Constructors

    | Improve this Doc View Source

    IndexSearcher(IndexReader)

    Creates a searcher searching the provided index.

    Declaration
    public IndexSearcher(IndexReader r)
    Parameters
    Type Name Description
    IndexReader r
    | Improve this Doc View Source

    IndexSearcher(IndexReader, TaskScheduler)

    Runs searches for each segment separately, using the provided . IndexSearcher will not shutdown/awaitTermination this on dispose; you must do so, eventually, on your own.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Declaration
    public IndexSearcher(IndexReader r, TaskScheduler executor)
    Parameters
    Type Name Description
    IndexReader r
    TaskScheduler executor
    | Improve this Doc View Source

    IndexSearcher(IndexReaderContext)

    Creates a searcher searching the provided top-level IndexReaderContext.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Declaration
    public IndexSearcher(IndexReaderContext context)
    Parameters
    Type Name Description
    IndexReaderContext context
    See Also
    IndexReaderContext
    Context
    | Improve this Doc View Source

    IndexSearcher(IndexReaderContext, TaskScheduler)

    Creates a searcher searching the provided top-level IndexReaderContext.

    Given a non-null this method runs searches for each segment separately, using the provided . IndexSearcher will not shutdown/awaitTermination this on close; you must do so, eventually, on your own.

    @lucene.experimental

    Declaration
    public IndexSearcher(IndexReaderContext context, TaskScheduler executor)
    Parameters
    Type Name Description
    IndexReaderContext context
    TaskScheduler executor
    See Also
    IndexReaderContext
    Context

    Fields

    | Improve this Doc View Source

    m_leafContexts

    Declaration
    protected readonly IList<AtomicReaderContext> m_leafContexts
    Field Value
    Type Description
    IList<AtomicReaderContext>
    | Improve this Doc View Source

    m_leafSlices

    Used with executor - each slice holds a set of leafs executed within one thread

    Declaration
    protected readonly IndexSearcher.LeafSlice[] m_leafSlices
    Field Value
    Type Description
    IndexSearcher.LeafSlice[]
    | Improve this Doc View Source

    m_readerContext

    Declaration
    protected readonly IndexReaderContext m_readerContext
    Field Value
    Type Description
    IndexReaderContext

    Properties

    | Improve this Doc View Source

    DefaultSimilarity

    Expert: returns a default Similarity instance. In general, this method is only called to initialize searchers and writers. User code and query implementations should respect Similarity.

    This is a Lucene.NET INTERNAL API, use at your own risk
    Declaration
    public static Similarity DefaultSimilarity { get; }
    Property Value
    Type Description
    Similarity
    | Improve this Doc View Source

    IndexReader

    Return the IndexReader this searches.

    Declaration
    public virtual IndexReader IndexReader { get; }
    Property Value
    Type Description
    IndexReader
    | Improve this Doc View Source

    Similarity

    Expert: Set the Similarity implementation used by this IndexSearcher.

    Declaration
    public virtual Similarity Similarity { get; set; }
    Property Value
    Type Description
    Similarity
    | Improve this Doc View Source

    TopReaderContext

    Returns this searchers the top-level IndexReaderContext.

    Declaration
    public virtual IndexReaderContext TopReaderContext { get; }
    Property Value
    Type Description
    IndexReaderContext
    See Also
    Context

    Methods

    | Improve this Doc View Source

    CollectionStatistics(String)

    Returns CollectionStatistics for a field.

    This can be overridden for example, to return a field's statistics across a distributed collection.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Declaration
    public virtual CollectionStatistics CollectionStatistics(string field)
    Parameters
    Type Name Description
    System.String field
    Returns
    Type Description
    CollectionStatistics
    | Improve this Doc View Source

    CreateNormalizedWeight(Query)

    Creates a normalized weight for a top-level Query. The query is rewritten by this method and CreateWeight(IndexSearcher) called, afterwards the Weight is normalized. The returned Weight can then directly be used to get a Scorer.

    This is a Lucene.NET INTERNAL API, use at your own risk
    Declaration
    public virtual Weight CreateNormalizedWeight(Query query)
    Parameters
    Type Name Description
    Query query
    Returns
    Type Description
    Weight
    | Improve this Doc View Source

    Doc(Int32)

    Sugar for

    .IndexReader.Document(docID)

    Declaration
    public virtual Document Doc(int docID)
    Parameters
    Type Name Description
    System.Int32 docID
    Returns
    Type Description
    Document
    See Also
    Document(System.Int32)
    | Improve this Doc View Source

    Doc(Int32, ISet<String>)

    Sugar for

    .IndexReader.Document(docID, fieldsToLoad)

    Declaration
    public virtual Document Doc(int docID, ISet<string> fieldsToLoad)
    Parameters
    Type Name Description
    System.Int32 docID
    ISet<System.String> fieldsToLoad
    Returns
    Type Description
    Document
    See Also
    Document(System.Int32, ISet<System.String>)
    | Improve this Doc View Source

    Doc(Int32, StoredFieldVisitor)

    Sugar for

    .IndexReader.Document(docID, fieldVisitor)

    Declaration
    public virtual void Doc(int docID, StoredFieldVisitor fieldVisitor)
    Parameters
    Type Name Description
    System.Int32 docID
    StoredFieldVisitor fieldVisitor
    See Also
    Document(System.Int32, StoredFieldVisitor)
    | Improve this Doc View Source

    Document(Int32, ISet<String>)

    Declaration
    public Document Document(int docID, ISet<string> fieldsToLoad)
    Parameters
    Type Name Description
    System.Int32 docID
    ISet<System.String> fieldsToLoad
    Returns
    Type Description
    Document
    | Improve this Doc View Source

    Explain(Query, Int32)

    Returns an Explanation that describes how doc scored against query.

    This is intended to be used in developing Similarity implementations, and, for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

    Declaration
    public virtual Explanation Explain(Query query, int doc)
    Parameters
    Type Name Description
    Query query
    System.Int32 doc
    Returns
    Type Description
    Explanation
    | Improve this Doc View Source

    Explain(Weight, Int32)

    Expert: low-level implementation method Returns an Explanation that describes how doc scored against weight.

    This is intended to be used in developing Similarity implementations, and, for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

    Applications should call Explain(Query, Int32).

    Declaration
    protected virtual Explanation Explain(Weight weight, int doc)
    Parameters
    Type Name Description
    Weight weight
    System.Int32 doc
    Returns
    Type Description
    Explanation
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Rewrite(Query)

    Expert: called to re-write queries into primitive queries.

    Declaration
    public virtual Query Rewrite(Query original)
    Parameters
    Type Name Description
    Query original
    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(IList<AtomicReaderContext>, Weight, FieldDoc, Int32, Sort, Boolean, Boolean, Boolean)

    Just like Search(Weight, Int32, Sort, Boolean, Boolean), but you choose whether or not the fields in the returned FieldDoc instances should be set by specifying fillFields.

    Declaration
    protected virtual TopFieldDocs Search(IList<AtomicReaderContext> leaves, Weight weight, FieldDoc after, int nDocs, Sort sort, bool fillFields, bool doDocScores, bool doMaxScore)
    Parameters
    Type Name Description
    IList<AtomicReaderContext> leaves
    Weight weight
    FieldDoc after
    System.Int32 nDocs
    Sort sort
    System.Boolean fillFields
    System.Boolean doDocScores
    System.Boolean doMaxScore
    Returns
    Type Description
    TopFieldDocs
    | Improve this Doc View Source

    Search(IList<AtomicReaderContext>, Weight, ICollector)

    Lower-level search API.

    Collect(Int32) is called for every document.

    NOTE: this method executes the searches on all given leaves exclusively. To search across all the searchers leaves use m_leafContexts.

    Declaration
    protected virtual void Search(IList<AtomicReaderContext> leaves, Weight weight, ICollector collector)
    Parameters
    Type Name Description
    IList<AtomicReaderContext> leaves

    The searchers leaves to execute the searches on

    Weight weight

    To match documents

    ICollector collector

    To receive hits

    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(IList<AtomicReaderContext>, Weight, ScoreDoc, Int32)

    Expert: Low-level search implementation. Finds the top

    n
    hits for query.

    Applications should usually call Search(Query, Int32) or Search(Query, Filter, Int32) instead.

    Declaration
    protected virtual TopDocs Search(IList<AtomicReaderContext> leaves, Weight weight, ScoreDoc after, int nDocs)
    Parameters
    Type Name Description
    IList<AtomicReaderContext> leaves
    Weight weight
    ScoreDoc after
    System.Int32 nDocs
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Filter, ICollector)

    Lower-level search API.

    Collect(Int32) is called for every matching document.

    Declaration
    public virtual void Search(Query query, Filter filter, ICollector results)
    Parameters
    Type Name Description
    Query query

    To match documents

    Filter filter

    Ef non-null, used to permit documents to be collected.

    ICollector results

    To receive hits

    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Filter, Int32)

    Finds the top n hits for query, applying filter if non-null.

    Declaration
    public virtual TopDocs Search(Query query, Filter filter, int n)
    Parameters
    Type Name Description
    Query query
    Filter filter
    System.Int32 n
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Filter, Int32, Sort)

    Search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.

    NOTE: this does not compute scores by default; use Search(Query, Filter, Int32, Sort, Boolean, Boolean) to control scoring.

    Declaration
    public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
    Parameters
    Type Name Description
    Query query
    Filter filter
    System.Int32 n
    Sort sort
    Returns
    Type Description
    TopFieldDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Filter, Int32, Sort, Boolean, Boolean)

    Search implementation with arbitrary sorting, plus control over whether hit scores and max score should be computed. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort. If doDocScores is true then the score of each hit will be computed and returned. If doMaxScore is true then the maximum score over all collected hits will be computed.

    Declaration
    public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore)
    Parameters
    Type Name Description
    Query query
    Filter filter
    System.Int32 n
    Sort sort
    System.Boolean doDocScores
    System.Boolean doMaxScore
    Returns
    Type Description
    TopFieldDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, ICollector)

    Lower-level search API.

    Collect(Int32) is called for every matching document.

    Declaration
    public virtual void Search(Query query, ICollector results)
    Parameters
    Type Name Description
    Query query
    ICollector results
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Int32)

    Finds the top n hits for query.

    Declaration
    public virtual TopDocs Search(Query query, int n)
    Parameters
    Type Name Description
    Query query
    System.Int32 n
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Query, Int32, Sort)

    Search implementation with arbitrary sorting and no filter.

    Declaration
    public virtual TopFieldDocs Search(Query query, int n, Sort sort)
    Parameters
    Type Name Description
    Query query

    The query to search for

    System.Int32 n

    Return only the top n results

    Sort sort

    The Sort object

    Returns
    Type Description
    TopFieldDocs

    The top docs, sorted according to the supplied Sort instance

    | Improve this Doc View Source

    Search(Weight, FieldDoc, Int32, Sort, Boolean, Boolean, Boolean)

    Just like Search(Weight, Int32, Sort, Boolean, Boolean), but you choose whether or not the fields in the returned FieldDoc instances should be set by specifying fillFields.

    Declaration
    protected virtual TopFieldDocs Search(Weight weight, FieldDoc after, int nDocs, Sort sort, bool fillFields, bool doDocScores, bool doMaxScore)
    Parameters
    Type Name Description
    Weight weight
    FieldDoc after
    System.Int32 nDocs
    Sort sort
    System.Boolean fillFields
    System.Boolean doDocScores
    System.Boolean doMaxScore
    Returns
    Type Description
    TopFieldDocs
    | Improve this Doc View Source

    Search(Weight, ScoreDoc, Int32)

    Expert: Low-level search implementation. Finds the top nDocs hits for query, applying filter if non-null.

    Applications should usually call Search(Query, Int32) or Search(Query, Filter, Int32) instead.

    Declaration
    protected virtual TopDocs Search(Weight weight, ScoreDoc after, int nDocs)
    Parameters
    Type Name Description
    Weight weight
    ScoreDoc after
    System.Int32 nDocs
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Search(Weight, Int32, Sort, Boolean, Boolean)

    Expert: Low-level search implementation with arbitrary sorting and control over whether hit scores and max score should be computed. Finds the top nDocs hits for query and sorting the hits by the criteria in sort.

    Applications should usually call Search(Query, Filter, Int32, Sort) instead.

    Declaration
    protected virtual TopFieldDocs Search(Weight weight, int nDocs, Sort sort, bool doDocScores, bool doMaxScore)
    Parameters
    Type Name Description
    Weight weight
    System.Int32 nDocs
    Sort sort
    System.Boolean doDocScores
    System.Boolean doMaxScore
    Returns
    Type Description
    TopFieldDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    SearchAfter(ScoreDoc, Query, Filter, Int32)

    Finds the top n hits for query, applying filter if non-null, where all results are after a previous result (after).

    By passing the bottom result from a previous page as after, this method can be used for efficient 'deep-paging' across potentially large result sets.

    Declaration
    public virtual TopDocs SearchAfter(ScoreDoc after, Query query, Filter filter, int n)
    Parameters
    Type Name Description
    ScoreDoc after
    Query query
    Filter filter
    System.Int32 n
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    SearchAfter(ScoreDoc, Query, Filter, Int32, Sort)

    Finds the top n hits for query, applying filter if non-null, where all results are after a previous result (after).

    By passing the bottom result from a previous page as after, this method can be used for efficient 'deep-paging' across potentially large result sets.

    Declaration
    public virtual TopDocs SearchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort)
    Parameters
    Type Name Description
    ScoreDoc after
    Query query
    Filter filter
    System.Int32 n
    Sort sort
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    SearchAfter(ScoreDoc, Query, Filter, Int32, Sort, Boolean, Boolean)

    Finds the top n hits for query where all results are after a previous result (after), allowing control over whether hit scores and max score should be computed.

    By passing the bottom result from a previous page as after, this method can be used for efficient 'deep-paging' across potentially large result sets. If doDocScores is true then the score of each hit will be computed and returned. If doMaxScore is true then the maximum score over all collected hits will be computed.

    Declaration
    public virtual TopDocs SearchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore)
    Parameters
    Type Name Description
    ScoreDoc after
    Query query
    Filter filter
    System.Int32 n
    Sort sort
    System.Boolean doDocScores
    System.Boolean doMaxScore
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    SearchAfter(ScoreDoc, Query, Int32)

    Finds the top n hits for top query where all results are after a previous result (top after).

    By passing the bottom result from a previous page as after, this method can be used for efficient 'deep-paging' across potentially large result sets.

    Declaration
    public virtual TopDocs SearchAfter(ScoreDoc after, Query query, int n)
    Parameters
    Type Name Description
    ScoreDoc after
    Query query
    System.Int32 n
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    SearchAfter(ScoreDoc, Query, Int32, Sort)

    Finds the top n hits for query where all results are after a previous result (after).

    By passing the bottom result from a previous page as after, this method can be used for efficient 'deep-paging' across potentially large result sets.

    Declaration
    public virtual TopDocs SearchAfter(ScoreDoc after, Query query, int n, Sort sort)
    Parameters
    Type Name Description
    ScoreDoc after
    Query query
    System.Int32 n
    Sort sort
    Returns
    Type Description
    TopDocs
    Exceptions
    Type Condition
    BooleanQuery.TooManyClausesException

    If a query would exceed MaxClauseCount clauses.

    | Improve this Doc View Source

    Slices(IList<AtomicReaderContext>)

    Expert: Creates an array of leaf slices each holding a subset of the given leaves. Each IndexSearcher.LeafSlice is executed in a single thread. By default there will be one IndexSearcher.LeafSlice per leaf (AtomicReaderContext).

    Declaration
    protected virtual IndexSearcher.LeafSlice[] Slices(IList<AtomicReaderContext> leaves)
    Parameters
    Type Name Description
    IList<AtomicReaderContext> leaves
    Returns
    Type Description
    IndexSearcher.LeafSlice[]
    | Improve this Doc View Source

    TermStatistics(Term, TermContext)

    Returns TermStatistics for a term.

    This can be overridden for example, to return a term's statistics across a distributed collection.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Declaration
    public virtual TermStatistics TermStatistics(Term term, TermContext context)
    Parameters
    Type Name Description
    Term term
    TermContext context
    Returns
    Type Description
    TermStatistics
    | Improve this Doc View Source

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    WrapFilter(Query, Filter)

    @lucene.internal

    Declaration
    protected virtual Query WrapFilter(Query query, Filter filter)
    Parameters
    Type Name Description
    Query query
    Filter filter
    Returns
    Type Description
    Query
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)