Class LTRScoringModel

java.lang.Object
org.apache.solr.ltr.model.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.

  • Field Details

  • Constructor Details

  • Method Details

    • getInstance

      public static LTRScoringModel getInstance(SolrResourceLoader solrResourceLoader, String className, String name, List<Feature> features, List<Normalizer> norms, String featureStoreName, List<Feature> allFeatures, Map<String,Object> params) throws ModelException
      Throws:
      ModelException
    • validate

      protected void validate() throws ModelException
      Validate that settings make sense and throws ModelException if they do not make sense.
      Throws:
      ModelException
    • getNorms

      public List<Normalizer> getNorms()
      Returns:
      the norms
    • getName

      public String getName()
      Returns:
      the name
    • getFeatures

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

      public Map<String,Object> getParams()
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • ramBytesUsed

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

      public Collection<Feature> getAllFeatures()
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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)