• API

    Show / Hide Table of Contents

    Class SimilarityBase

    A subclass of Similarity that provides a simplified API for its descendants. Subclasses are only required to implement the Score(BasicStats, Single, Single) and ToString() methods. Implementing Explain(Explanation, BasicStats, Int32, Single, Single) is optional, inasmuch as SimilarityBase already provides a basic explanation of the score and the term frequency. However, implementers of a subclass are encouraged to include as much detail about the scoring method as possible.

    Note: multi-word queries such as phrase queries are scored in a different way than Lucene's default ranking algorithm: whereas it "fakes" an IDF value for the phrase as a whole (since it does not know it), this class instead scores phrases as a summation of the individual term scores.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Inheritance
    System.Object
    Similarity
    SimilarityBase
    DFRSimilarity
    IBSimilarity
    LMSimilarity
    Inherited Members
    Similarity.Coord(Int32, Int32)
    Similarity.QueryNorm(Single)
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Lucene.Net.Search.Similarities
    Assembly: Lucene.Net.dll
    Syntax
    public abstract class SimilarityBase : Similarity

    Constructors

    | Improve this Doc View Source

    SimilarityBase()

    Sole constructor. (For invocation by subclass constructors, typically implicit.)

    Declaration
    public SimilarityBase()

    Properties

    | Improve this Doc View Source

    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.

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk
    Declaration
    public virtual bool DiscountOverlaps { get; set; }
    Property Value
    Type Description
    System.Boolean
    See Also
    ComputeNorm(FieldInvertState)

    Methods

    | Improve this Doc View Source

    ComputeNorm(FieldInvertState)

    Encodes the document length in the same way as TFIDFSimilarity.

    Declaration
    public override long ComputeNorm(FieldInvertState state)
    Parameters
    Type Name Description
    FieldInvertState state
    Returns
    Type Description
    System.Int64
    Overrides
    Similarity.ComputeNorm(FieldInvertState)
    | Improve this Doc View Source

    ComputeWeight(Single, CollectionStatistics, TermStatistics[])

    Declaration
    public override sealed Similarity.SimWeight ComputeWeight(float queryBoost, CollectionStatistics collectionStats, params TermStatistics[] termStats)
    Parameters
    Type Name Description
    System.Single queryBoost
    CollectionStatistics collectionStats
    TermStatistics[] termStats
    Returns
    Type Description
    Similarity.SimWeight
    Overrides
    Similarity.ComputeWeight(Single, CollectionStatistics, TermStatistics[])
    | Improve this Doc View Source

    DecodeNormValue(Byte)

    Decodes a normalization factor (document length) stored in an index.

    Declaration
    protected virtual float DecodeNormValue(byte norm)
    Parameters
    Type Name Description
    System.Byte norm
    Returns
    Type Description
    System.Single
    | Improve this Doc View Source

    EncodeNormValue(Single, Single)

    Encodes the length to a byte via SmallSingle.

    Declaration
    protected virtual byte EncodeNormValue(float boost, float length)
    Parameters
    Type Name Description
    System.Single boost
    System.Single length
    Returns
    Type Description
    System.Byte
    | Improve this Doc View Source

    Explain(Explanation, BasicStats, Int32, Single, Single)

    Subclasses should implement this method to explain the score. expl already contains the score, the name of the class and the doc id, as well as the term frequency and its explanation; subclasses can add additional clauses to explain details of their scoring formulae.

    The default implementation does nothing.

    Declaration
    protected virtual void Explain(Explanation expl, BasicStats stats, int doc, float freq, float docLen)
    Parameters
    Type Name Description
    Explanation expl

    the explanation to extend with details.

    BasicStats stats

    the corpus level statistics.

    System.Int32 doc

    the document id.

    System.Single freq

    the term frequency.

    System.Single docLen

    the document length.

    | Improve this Doc View Source

    Explain(BasicStats, Int32, Explanation, Single)

    Explains the score. The implementation here provides a basic explanation in the format Score(name-of-similarity, doc=doc-id, freq=term-frequency), computed from:, and attaches the score (computed via the Score(BasicStats, Single, Single) method) and the explanation for the term frequency. Subclasses content with this format may add additional details in Explain(Explanation, BasicStats, Int32, Single, Single).

    Declaration
    public virtual Explanation Explain(BasicStats stats, int doc, Explanation freq, float docLen)
    Parameters
    Type Name Description
    BasicStats stats

    the corpus level statistics.

    System.Int32 doc

    the document id.

    Explanation freq

    the term frequency and its explanation.

    System.Single docLen

    the document length.

    Returns
    Type Description
    Explanation

    the explanation.

    | Improve this Doc View Source

    FillBasicStats(BasicStats, CollectionStatistics, TermStatistics)

    Fills all member fields defined in BasicStats in stats. Subclasses can override this method to fill additional stats.

    Declaration
    protected virtual void FillBasicStats(BasicStats stats, CollectionStatistics collectionStats, TermStatistics termStats)
    Parameters
    Type Name Description
    BasicStats stats
    CollectionStatistics collectionStats
    TermStatistics termStats
    | Improve this Doc View Source

    GetSimScorer(Similarity.SimWeight, AtomicReaderContext)

    Declaration
    public override Similarity.SimScorer GetSimScorer(Similarity.SimWeight stats, AtomicReaderContext context)
    Parameters
    Type Name Description
    Similarity.SimWeight stats
    AtomicReaderContext context
    Returns
    Type Description
    Similarity.SimScorer
    Overrides
    Similarity.GetSimScorer(Similarity.SimWeight, AtomicReaderContext)
    | Improve this Doc View Source

    Log2(Double)

    Returns the base two logarithm of x.

    Declaration
    public static double Log2(double x)
    Parameters
    Type Name Description
    System.Double x
    Returns
    Type Description
    System.Double
    | Improve this Doc View Source

    NewStats(String, Single)

    Factory method to return a custom stats object

    Declaration
    protected virtual BasicStats NewStats(string field, float queryBoost)
    Parameters
    Type Name Description
    System.String field
    System.Single queryBoost
    Returns
    Type Description
    BasicStats
    | Improve this Doc View Source

    Score(BasicStats, Single, Single)

    Scores the document doc.

    Subclasses must apply their scoring formula in this class.

    Declaration
    public abstract float Score(BasicStats stats, float freq, float docLen)
    Parameters
    Type Name Description
    BasicStats stats

    the corpus level statistics.

    System.Single freq

    the term frequency.

    System.Single docLen

    the document length.

    Returns
    Type Description
    System.Single

    the score.

    | Improve this Doc View Source

    ToString()

    Subclasses must override this method to return the name of the Similarity and preferably the values of parameters (if any) as well.

    Declaration
    public abstract override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.Object.ToString()
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)