Package org.apache.solr.ltr.model
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" : { ... } }LTRScoringModelis an abstract class and concrete classes must implement thescore(float[])andexplain(LeafReaderContext, int, float, List)methods.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)abstract org.apache.lucene.search.Explanationexplain(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.Collection<Feature>getAllFeatures()List<Feature>getFeatures()StringgetFeatureStoreName()static LTRScoringModelgetInstance(SolrResourceLoader solrResourceLoader, String className, String name, List<Feature> features, List<Normalizer> norms, String featureStoreName, List<Feature> allFeatures, Map<String,Object> params)StringgetName()org.apache.lucene.search.ExplanationgetNormalizerExplanation(org.apache.lucene.search.Explanation e, int idx)List<Normalizer>getNorms()Map<String,Object>getParams()inthashCode()voidnormalizeFeaturesInPlace(float[] modelFeatureValues)Goes through all the stored feature values, and calculates the normalized values for all the features that will be used for scoring.longramBytesUsed()abstract floatscore(float[] modelFeatureValuesNormalized)Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.StringtoString()protected voidvalidate()Validate that settings make sense and throwsModelExceptionif they do not make sense.
-
-
-
Field Detail
-
name
protected final String name
-
norms
protected final List<Normalizer> norms
-
-
Method Detail
-
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 ModelExceptionValidate that settings make sense and throwsModelExceptionif they do not make sense.- Throws:
ModelException
-
getNorms
public List<Normalizer> getNorms()
- Returns:
- the norms
-
getName
public String getName()
- Returns:
- the name
-
ramBytesUsed
public long ramBytesUsed()
- Specified by:
ramBytesUsedin interfaceorg.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 indoc- Document to explainfinalScore- Original scorefeatureExplanations- 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)
-
-