Show / Hide Table of Contents

    Class Weight

    Expert: Calculate query weights and build query scorers.

    The purpose of Weight is to ensure searching does not modify a Query, so that a Query instance can be reused.

    IndexSearcher dependent state of the query should reside in the Weight.

    AtomicReader dependent state should reside in the Scorer.

    Since Weight creates Scorer instances for a given AtomicReaderContext (GetScorer(AtomicReaderContext, IBits)) callers must maintain the relationship between the searcher's top-level IndexReaderContext and the context used to create a Scorer.

    A Weight is used in the following way:

    1. A Weight is constructed by a top-level query, given a IndexSearcher (CreateWeight(IndexSearcher)).
    2. The GetValueForNormalization() method is called on the Weight to compute the query normalization factor QueryNorm(Single) of the query clauses contained in the query.
    3. The query normalization factor is passed to Normalize(Single, Single). At this point the weighting is complete.
    4. A Scorer is constructed by GetScorer(AtomicReaderContext, IBits).

    @since 2.9

    Inheritance
    System.Object
    Weight
    BooleanQuery.BooleanWeight
    ConstantScoreQuery.ConstantWeight
    DisjunctionMaxQuery.DisjunctionMaxWeight
    SpanWeight
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public abstract class Weight : object

    Properties

    | Improve this Doc View Source

    Query

    The query that this concerns.

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

    ScoresDocsOutOfOrder

    Returns true if this implementation scores docs only out of order. This method is used in conjunction with ICollector's AcceptsDocsOutOfOrder and GetBulkScorer(AtomicReaderContext, Boolean, IBits) to create a matching Scorer instance for a given ICollector, or vice versa.

    NOTE: the default implementation returns false, i.e. the Scorer scores documents in-order.

    Declaration
    public virtual bool ScoresDocsOutOfOrder { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    | Improve this Doc View Source

    Explain(AtomicReaderContext, Int32)

    An explanation of the score computation for the named document.

    Declaration
    public abstract Explanation Explain(AtomicReaderContext context, int doc)
    Parameters
    Type Name Description
    AtomicReaderContext context

    The readers context to create the Explanation for.

    System.Int32 doc

    The document's id relative to the given context's reader

    Returns
    Type Description
    Explanation

    An Explanation for the score

    | Improve this Doc View Source

    GetBulkScorer(AtomicReaderContext, Boolean, IBits)

    Optional method, to return a BulkScorer to score the query and send hits to a ICollector. Only queries that have a different top-level approach need to override this; the default implementation pulls a normal Scorer and iterates and collects the resulting hits.

    Declaration
    public virtual BulkScorer GetBulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, IBits acceptDocs)
    Parameters
    Type Name Description
    AtomicReaderContext context

    The AtomicReaderContext for which to return the Scorer.

    System.Boolean scoreDocsInOrder

    Specifies whether in-order scoring of documents is required. Note that if set to false (i.e., out-of-order scoring is required), this method can return whatever scoring mode it supports, as every in-order scorer is also an out-of-order one. However, an out-of-order scorer may not support NextDoc() and/or Advance(Int32), therefore it is recommended to request an in-order scorer if use of these methods is required.

    IBits acceptDocs

    IBits that represent the allowable docs to match (typically deleted docs but possibly filtering other documents)

    Returns
    Type Description
    BulkScorer

    A BulkScorer which scores documents and passes them to a collector.

    | Improve this Doc View Source

    GetScorer(AtomicReaderContext, IBits)

    Returns a Scorer which scores documents in/out-of order according to scoreDocsInOrder.

    NOTE: even if scoreDocsInOrder is false, it is recommended to check whether the returned Scorer indeed scores documents out of order (i.e., call ScoresDocsOutOfOrder), as some Scorer implementations will always return documents in-order.

    NOTE: null can be returned if no documents will be scored by this query.

    Declaration
    public abstract Scorer GetScorer(AtomicReaderContext context, IBits acceptDocs)
    Parameters
    Type Name Description
    AtomicReaderContext context

    The AtomicReaderContext for which to return the Scorer.

    IBits acceptDocs

    IBits that represent the allowable docs to match (typically deleted docs but possibly filtering other documents)

    Returns
    Type Description
    Scorer

    A Scorer which scores documents in/out-of order.

    | Improve this Doc View Source

    GetValueForNormalization()

    The value for normalization of contained query clauses (e.g. sum of squared weights).

    Declaration
    public abstract float GetValueForNormalization()
    Returns
    Type Description
    System.Single
    | Improve this Doc View Source

    Normalize(Single, Single)

    Assigns the query normalization factor and boost from parent queries to this.

    Declaration
    public abstract void Normalize(float norm, float topLevelBoost)
    Parameters
    Type Name Description
    System.Single norm
    System.Single topLevelBoost
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)