Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class CustomScoreProvider

    An instance of this subclass should be returned by GetCustomScoreProvider(AtomicReaderContext), if you want to modify the custom score calculation of a CustomScoreQuery.

    Since Lucene 2.9, queries operate on each segment of an index separately, so the protected m_context field can be used to resolve doc IDs, as the supplied doc ID is per-segment and without knowledge of the Lucene.Net.Index.IndexReader you cannot access the document or Lucene.Net.Search.IFieldCache.

    Note

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

    @since 2.9.2

    Inheritance
    object
    CustomScoreProvider
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Queries
    Assembly: Lucene.Net.Queries.dll
    Syntax
    public class CustomScoreProvider

    Constructors

    CustomScoreProvider(AtomicReaderContext)

    Creates a new instance of the provider class for the given Lucene.Net.Index.IndexReader.

    Declaration
    public CustomScoreProvider(AtomicReaderContext context)
    Parameters
    Type Name Description
    AtomicReaderContext context

    Fields

    m_context

    An instance of this subclass should be returned by GetCustomScoreProvider(AtomicReaderContext), if you want to modify the custom score calculation of a CustomScoreQuery.

    Since Lucene 2.9, queries operate on each segment of an index separately, so the protected m_context field can be used to resolve doc IDs, as the supplied doc ID is per-segment and without knowledge of the Lucene.Net.Index.IndexReader you cannot access the document or Lucene.Net.Search.IFieldCache.

    Note

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

    @since 2.9.2

    Declaration
    protected readonly AtomicReaderContext m_context
    Field Value
    Type Description
    AtomicReaderContext

    Methods

    CustomExplain(int, Explanation, Explanation)

    Explain the custom score. Whenever overriding CustomScore(int, float, float), this method should also be overridden to provide the correct explanation for the part of the custom scoring.

    Declaration
    public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
    Parameters
    Type Name Description
    int doc

    doc being explained.

    Explanation subQueryExpl

    explanation for the sub-query part.

    Explanation valSrcExpl

    explanation for the value source part.

    Returns
    Type Description
    Explanation

    an explanation for the custom score

    CustomExplain(int, Explanation, Explanation[])

    Explain the custom score. Whenever overriding CustomScore(int, float, float[]), this method should also be overridden to provide the correct explanation for the part of the custom scoring.

    Declaration
    public virtual Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
    Parameters
    Type Name Description
    int doc

    doc being explained.

    Explanation subQueryExpl

    explanation for the sub-query part.

    Explanation[] valSrcExpls

    explanation for the value source part.

    Returns
    Type Description
    Explanation

    an explanation for the custom score

    CustomScore(int, float, float)

    Compute a custom score by the subQueryScore and the FunctionQuery score.

    Subclasses can override this method to modify the custom score.

    If your custom scoring is different than the default herein you should override at least one of the two CustomScore(int, float, float) methods. If the number of FunctionQuerys is always < 2 it is sufficient to override this CustomScore(int, float, float) method, which is simpler.

    The default computation herein is a multiplication of the two scores:
    ModifiedScore = subQueryScore * valSrcScore
    Declaration
    public virtual float CustomScore(int doc, float subQueryScore, float valSrcScore)
    Parameters
    Type Name Description
    int doc

    id of scored doc.

    float subQueryScore

    score of that doc by the subQuery.

    float valSrcScore

    score of that doc by the FunctionQuery.

    Returns
    Type Description
    float

    custom score.

    CustomScore(int, float, float[])

    Compute a custom score by the subQuery score and a number of FunctionQuery scores.

    Subclasses can override this method to modify the custom score.

    If your custom scoring is different than the default herein you should override at least one of the two CustomScore(int, float, float) methods. If the number of FunctionQuerys is always < 2 it is sufficient to override the other CustomScore(int, float, float) method, which is simpler.

    The default computation herein is a multiplication of given scores:
    ModifiedScore = valSrcScore * valSrcScores[0] * valSrcScores[1] * ...
    Declaration
    public virtual float CustomScore(int doc, float subQueryScore, float[] valSrcScores)
    Parameters
    Type Name Description
    int doc

    id of scored doc.

    float subQueryScore

    score of that doc by the subQuery.

    float[] valSrcScores

    scores of that doc by the FunctionQuery.

    Returns
    Type Description
    float

    custom score.

    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.