Class LTRScoringModel

  • All Implemented Interfaces:
    org.apache.lucene.util.Accountable
    Direct Known Subclasses:
    AdapterModel, LinearModel, MultipleAdditiveTreesModel, NeuralNetworkModel

    public abstract class LTRScoringModel
    extends Object
    implements org.apache.lucene.util.Accountable
    A scoring model computes scores that can be used to rerank documents.

    A scoring model consists of

    • a list of features (Feature) and
    • a list of normalizers (Normalizer) plus
    • parameters or configuration to represent the scoring algorithm.

    Example configuration (snippet):

     {
       "class" : "...",
       "name" : "myModelName",
       "features" : [
         {
           "name" : "isBook"
         },
         {
           "name" : "originalScore",
           "norm": {
             "class" : "org.apache.solr.ltr.norm.StandardNormalizer",
             "params" : { "avg":"100", "std":"10" }
           }
         },
         {
           "name" : "price",
           "norm": {
             "class" : "org.apache.solr.ltr.norm.MinMaxNormalizer",
             "params" : { "min":"0", "max":"1000" }
           }
         }
       ],
       "params" : {
         ...
       }
     }
     

    LTRScoringModel is an abstract class and concrete classes must implement the score(float[]) and explain(LeafReaderContext, int, float, List) methods.

    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • getFeatures

        public List<Feature> getFeatures()
        Returns:
        the features
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • ramBytesUsed

        public long ramBytesUsed()
        Specified by:
        ramBytesUsed in interface org.apache.lucene.util.Accountable
      • getFeatureStoreName

        public String getFeatureStoreName()
      • score

        public abstract float score​(float[] modelFeatureValuesNormalized)
        Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.
        Parameters:
        modelFeatureValuesNormalized - List of normalized feature values. Each feature is identified by its id, which is the index in the array
        Returns:
        The final score for a document
      • explain

        public abstract org.apache.lucene.search.Explanation explain​(org.apache.lucene.index.LeafReaderContext context,
                                                                     int doc,
                                                                     float finalScore,
                                                                     List<org.apache.lucene.search.Explanation> featureExplanations)
        Similar to the score() function, except it returns an explanation of how the features were used to calculate the score.
        Parameters:
        context - Context the document is in
        doc - Document to explain
        finalScore - Original score
        featureExplanations - Explanations for each feature calculation
        Returns:
        Explanation for the scoring of a document
      • normalizeFeaturesInPlace

        public void normalizeFeaturesInPlace​(float[] modelFeatureValues)
        Goes through all the stored feature values, and calculates the normalized values for all the features that will be used for scoring.
      • getNormalizerExplanation

        public org.apache.lucene.search.Explanation getNormalizerExplanation​(org.apache.lucene.search.Explanation e,
                                                                             int idx)