Package org.apache.solr.ltr.model
Class WrapperModel
- java.lang.Object
-
- org.apache.solr.ltr.model.LTRScoringModel
-
- org.apache.solr.ltr.model.AdapterModel
-
- org.apache.solr.ltr.model.WrapperModel
-
- All Implemented Interfaces:
org.apache.lucene.util.Accountable
- Direct Known Subclasses:
DefaultWrapperModel
public abstract class WrapperModel extends AdapterModel
A scoring model that wraps the other model.This model loads a model from an external resource during the initialization. The way of fetching the wrapped model is depended on the implementation of
fetchModelMap()
.This model doesn't hold the actual parameters of the wrapped model, thus it can manage large models which are difficult to upload to ZooKeeper.
Example configuration:
{ "class": "...", "name": "myModelName", "params": { ... } }
NOTE: no "features" are configured in the wrapper model because the wrapped model's features will be used instead. Also note that if a "store" is configured for the wrapper model then it must match the "store" of the wrapped model.
-
-
Field Summary
Fields Modifier and Type Field Description protected LTRScoringModel
model
-
Fields inherited from class org.apache.solr.ltr.model.AdapterModel
solrResourceLoader
-
Fields inherited from class org.apache.solr.ltr.model.LTRScoringModel
features, name, norms
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
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.abstract Map<String,Object>
fetchModelMap()
Collection<Feature>
getAllFeatures()
List<Feature>
getFeatures()
org.apache.lucene.search.Explanation
getNormalizerExplanation(org.apache.lucene.search.Explanation e, int idx)
List<Normalizer>
getNorms()
int
hashCode()
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.long
ramBytesUsed()
float
score(float[] modelFeatureValuesNormalized)
Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.String
toString()
void
updateModel(LTRScoringModel model)
protected void
validate()
Validate that settings make sense and throwsModelException
if they do not make sense.-
Methods inherited from class org.apache.solr.ltr.model.AdapterModel
init
-
Methods inherited from class org.apache.solr.ltr.model.LTRScoringModel
getFeatureStoreName, getInstance, getName, getParams
-
-
-
-
Field Detail
-
model
protected LTRScoringModel model
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classLTRScoringModel
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classLTRScoringModel
-
validate
protected void validate() throws ModelException
Description copied from class:LTRScoringModel
Validate that settings make sense and throwsModelException
if they do not make sense.- Overrides:
validate
in classLTRScoringModel
- Throws:
ModelException
-
updateModel
public void updateModel(LTRScoringModel model)
-
fetchModelMap
public abstract Map<String,Object> fetchModelMap() throws ModelException
- Throws:
ModelException
-
getNorms
public List<Normalizer> getNorms()
- Overrides:
getNorms
in classLTRScoringModel
- Returns:
- the norms
-
getFeatures
public List<Feature> getFeatures()
- Overrides:
getFeatures
in classLTRScoringModel
- Returns:
- the features
-
getAllFeatures
public Collection<Feature> getAllFeatures()
- Overrides:
getAllFeatures
in classLTRScoringModel
-
ramBytesUsed
public long ramBytesUsed()
- Specified by:
ramBytesUsed
in interfaceorg.apache.lucene.util.Accountable
- Overrides:
ramBytesUsed
in classLTRScoringModel
-
score
public float score(float[] modelFeatureValuesNormalized)
Description copied from class:LTRScoringModel
Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.- Specified by:
score
in classLTRScoringModel
- 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 org.apache.lucene.search.Explanation explain(org.apache.lucene.index.LeafReaderContext context, int doc, float finalScore, List<org.apache.lucene.search.Explanation> featureExplanations)
Description copied from class:LTRScoringModel
Similar to the score() function, except it returns an explanation of how the features were used to calculate the score.- Specified by:
explain
in classLTRScoringModel
- 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)
Description copied from class:LTRScoringModel
Goes through all the stored feature values, and calculates the normalized values for all the features that will be used for scoring.- Overrides:
normalizeFeaturesInPlace
in classLTRScoringModel
-
getNormalizerExplanation
public org.apache.lucene.search.Explanation getNormalizerExplanation(org.apache.lucene.search.Explanation e, int idx)
- Overrides:
getNormalizerExplanation
in classLTRScoringModel
-
toString
public String toString()
- Overrides:
toString
in classLTRScoringModel
-
-