Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class DefaultSimilarity

    Expert: Default scoring implementation which encodes (EncodeNormValue(float)) norm values as a single byte before being stored. At search time, the norm byte value is read from the index Directory and decoded (DecodeNormValue(long)) back to a float norm value. this encoding/decoding, while reducing index size, comes with the price of precision loss - it is not guaranteed that Decode(Encode(x)) = x. For instance, Decode(Encode(0.89)) = 0.75.

    Compression of norm values to a single byte saves memory at search time, because once a field is referenced at search time, its norms - for all documents - are maintained in memory.

    The rationale supporting such lossy compression of norm values is that given the difficulty (and inaccuracy) of users to express their true information need by a query, only big differences matter.

    Last, note that search time is too late to modify this norm part of scoring, e.g. by using a different Similarity for search.
    Inheritance
    object
    Similarity
    TFIDFSimilarity
    DefaultSimilarity
    Inherited Members
    TFIDFSimilarity.IdfExplain(CollectionStatistics, TermStatistics)
    TFIDFSimilarity.IdfExplain(CollectionStatistics, TermStatistics[])
    TFIDFSimilarity.ComputeNorm(FieldInvertState)
    TFIDFSimilarity.ComputeWeight(float, CollectionStatistics, params TermStatistics[])
    TFIDFSimilarity.GetSimScorer(Similarity.SimWeight, AtomicReaderContext)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Search.Similarities
    Assembly: Lucene.Net.dll
    Syntax
    public class DefaultSimilarity : TFIDFSimilarity

    Constructors

    DefaultSimilarity()

    Sole constructor: parameter-free

    Declaration
    public DefaultSimilarity()

    Fields

    m_discountOverlaps

    True if overlap tokens (tokens with a position of increment of zero) are discounted from the document's length.

    Declaration
    protected bool m_discountOverlaps
    Field Value
    Type Description
    bool

    Properties

    DiscountOverlaps

    Determines whether overlap tokens (Tokens with 0 position increment) are ignored when computing norm. By default this is true, meaning overlap tokens do not count when computing norms.

    Note

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

    Declaration
    public virtual bool DiscountOverlaps { get; set; }
    Property Value
    Type Description
    bool
    See Also
    ComputeNorm(FieldInvertState)

    Methods

    Coord(int, int)

    Implemented as overlap / maxOverlap.

    Declaration
    public override float Coord(int overlap, int maxOverlap)
    Parameters
    Type Name Description
    int overlap
    int maxOverlap
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.Coord(int, int)

    DecodeNormValue(long)

    Decodes the norm value, assuming it is a single byte.

    Declaration
    public override sealed float DecodeNormValue(long norm)
    Parameters
    Type Name Description
    long norm
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.DecodeNormValue(long)
    See Also
    EncodeNormValue(float)

    EncodeNormValue(float)

    Encodes a normalization factor for storage in an index.

    The encoding uses a three-bit mantissa, a five-bit exponent, and the zero-exponent point at 15, thus representing values from around 7x10^9 to 2x10^-9 with about one significant decimal digit of accuracy. Zero is also represented. Negative numbers are rounded up to zero. Values too large to represent are rounded down to the largest representable value. Positive values too small to represent are rounded up to the smallest positive representable value.
    Declaration
    public override sealed long EncodeNormValue(float f)
    Parameters
    Type Name Description
    float f
    Returns
    Type Description
    long
    Overrides
    TFIDFSimilarity.EncodeNormValue(float)
    See Also
    Boost
    SmallSingle

    Idf(long, long)

    Implemented as log(numDocs/(docFreq+1)) + 1.

    Declaration
    public override float Idf(long docFreq, long numDocs)
    Parameters
    Type Name Description
    long docFreq
    long numDocs
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.Idf(long, long)

    LengthNorm(FieldInvertState)

    Implemented as state.Boost * LengthNorm(numTerms), where numTerms is Length if DiscountOverlaps is false, else it's Length - NumOverlap.

    Note

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

    Declaration
    public override float LengthNorm(FieldInvertState state)
    Parameters
    Type Name Description
    FieldInvertState state
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.LengthNorm(FieldInvertState)

    QueryNorm(float)

    Implemented as 1/sqrt(sumOfSquaredWeights).

    Declaration
    public override float QueryNorm(float sumOfSquaredWeights)
    Parameters
    Type Name Description
    float sumOfSquaredWeights
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.QueryNorm(float)

    ScorePayload(int, int, int, BytesRef)

    The default implementation returns 1

    Declaration
    public override float ScorePayload(int doc, int start, int end, BytesRef payload)
    Parameters
    Type Name Description
    int doc
    int start
    int end
    BytesRef payload
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.ScorePayload(int, int, int, BytesRef)

    SloppyFreq(int)

    Implemented as 1 / (distance + 1).

    Declaration
    public override float SloppyFreq(int distance)
    Parameters
    Type Name Description
    int distance
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.SloppyFreq(int)

    Tf(float)

    Implemented as Math.Sqrt(freq).

    Declaration
    public override float Tf(float freq)
    Parameters
    Type Name Description
    float freq
    Returns
    Type Description
    float
    Overrides
    TFIDFSimilarity.Tf(float)

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()
    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.