org.apache.lucene.search.similarities

Class SimilarityBase

    • Field Detail

      • discountOverlaps

        protected boolean discountOverlaps
        True if overlap tokens (tokens with a position of increment of zero) are discounted from the document's length.
    • Constructor Detail

      • SimilarityBase

        public SimilarityBase()
        Sole constructor. (For invocation by subclass constructors, typically implicit.)
    • Method Detail

      • computeWeight

        public final Similarity.SimWeight computeWeight(CollectionStatistics collectionStats,
                                                        TermStatistics... termStats)
        Description copied from class: Similarity
        Compute any collection-level weight (e.g. IDF, average document length, etc) needed for scoring a query.
        Specified by:
        computeWeight in class Similarity
        Parameters:
        collectionStats - collection-level statistics, such as the number of tokens in the collection.
        termStats - term-level statistics, such as the document frequency of a term across the collection.
        Returns:
        SimWeight object with the information this Similarity needs to score a query.
      • score

        protected abstract float score(BasicStats stats,
                                       float freq,
                                       float docLen)
        Scores the document doc.

        Subclasses must apply their scoring formula in this class.

        Parameters:
        stats - the corpus level statistics.
        freq - the term frequency.
        docLen - the document length.
        Returns:
        the score.
      • explain

        protected void explain(List<Explanation> subExpls,
                               BasicStats stats,
                               int doc,
                               float freq,
                               float docLen)
        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.

        Parameters:
        subExpls - the list of details of the explanation to extend
        stats - the corpus level statistics.
        doc - the document id.
        freq - the term frequency.
        docLen - the document length.
      • explain

        protected Explanation explain(BasicStats stats,
                                      int doc,
                                      Explanation freq,
                                      float docLen)
        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, float, float) method) and the explanation for the term frequency. Subclasses content with this format may add additional details in explain(List, BasicStats, int, float, float).
        Parameters:
        stats - the corpus level statistics.
        doc - the document id.
        freq - the term frequency and its explanation.
        docLen - the document length.
        Returns:
        the explanation.
      • toString

        public abstract String toString()
        Subclasses must override this method to return the name of the Similarity and preferably the values of parameters (if any) as well.
        Overrides:
        toString in class Object
      • encodeNormValue

        protected byte encodeNormValue(float boost,
                                       float length)
        Encodes the length to a byte via SmallFloat.
      • log2

        public static double log2(double x)
        Returns the base two logarithm of x.