Class LTRScoringModel

  • All Implemented Interfaces:
    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()
        the name
      • getFeatures

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

        public int hashCode()
        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.
        modelFeatureValuesNormalized - List of normalized feature values. Each feature is identified by its id, which is the index in the array
        The final score for a document
      • explain

        public abstract explain​(org.apache.lucene.index.LeafReaderContext context,
                                                                     int doc,
                                                                     float finalScore,
                                                                     List<> featureExplanations)
        Similar to the score() function, except it returns an explanation of how the features were used to calculate the score.
        context - Context the document is in
        doc - Document to explain
        finalScore - Original score
        featureExplanations - Explanations for each feature calculation
        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 getNormalizerExplanation​( e,
                                                                             int idx)