Class CustomScoreProvider
- java.lang.Object
-
- org.apache.lucene.queries.CustomScoreProvider
-
public class CustomScoreProvider extends java.lang.Object
An instance of this subclass should be returned byCustomScoreQuery.getCustomScoreProvider(org.apache.lucene.index.AtomicReaderContext)
, if you want to modify the custom score calculation of aCustomScoreQuery
.Since Lucene 2.9, queries operate on each segment of an index separately, so the protected
context
field can be used to resolve doc IDs, as the supplieddoc
ID is per-segment and without knowledge of the IndexReader you cannot access the document orFieldCache
.- Since:
- 2.9.2
-
-
Constructor Summary
Constructors Constructor Description CustomScoreProvider(AtomicReaderContext context)
Creates a new instance of the provider class for the givenIndexReader
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Explanation
customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
Explain the custom score.Explanation
customExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
Explain the custom score.float
customScore(int doc, float subQueryScore, float valSrcScore)
Compute a custom score by the subQuery score and theFunctionQuery
score.float
customScore(int doc, float subQueryScore, float[] valSrcScores)
Compute a custom score by the subQuery score and a number ofFunctionQuery
scores.
-
-
-
Constructor Detail
-
CustomScoreProvider
public CustomScoreProvider(AtomicReaderContext context)
Creates a new instance of the provider class for the givenIndexReader
.
-
-
Method Detail
-
customScore
public float customScore(int doc, float subQueryScore, float[] valSrcScores) throws java.io.IOException
Compute a custom score by the subQuery score and a number ofFunctionQuery
scores.Subclasses can override this method to modify the custom score.
If your custom scoring is different than the default herein you should override at least one of the two customScore() methods. If the number of
function queries
is always < 2 it is sufficient to override the othercustomScore()
method, which is simpler.The default computation herein is a multiplication of given scores:
ModifiedScore = valSrcScore * valSrcScores[0] * valSrcScores[1] * ...
- Parameters:
doc
- id of scored doc.subQueryScore
- score of that doc by the subQuery.valSrcScores
- scores of that doc by theFunctionQuery
.- Returns:
- custom score.
- Throws:
java.io.IOException
-
customScore
public float customScore(int doc, float subQueryScore, float valSrcScore) throws java.io.IOException
Compute a custom score by the subQuery score and theFunctionQuery
score.Subclasses can override this method to modify the custom score.
If your custom scoring is different than the default herein you should override at least one of the two customScore() methods. If the number of
function queries
is always < 2 it is sufficient to override this customScore() method, which is simpler.The default computation herein is a multiplication of the two scores:
ModifiedScore = subQueryScore * valSrcScore
- Parameters:
doc
- id of scored doc.subQueryScore
- score of that doc by the subQuery.valSrcScore
- score of that doc by theFunctionQuery
.- Returns:
- custom score.
- Throws:
java.io.IOException
-
customExplain
public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls) throws java.io.IOException
Explain the custom score. Whenever overridingcustomScore(int, float, float[])
, this method should also be overridden to provide the correct explanation for the part of the custom scoring.- Parameters:
doc
- doc being explained.subQueryExpl
- explanation for the sub-query part.valSrcExpls
- explanation for the value source part.- Returns:
- an explanation for the custom score
- Throws:
java.io.IOException
-
customExplain
public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl) throws java.io.IOException
Explain the custom score. Whenever overridingcustomScore(int, float, float)
, this method should also be overridden to provide the correct explanation for the part of the custom scoring.- Parameters:
doc
- doc being explained.subQueryExpl
- explanation for the sub-query part.valSrcExpl
- explanation for the value source part.- Returns:
- an explanation for the custom score
- Throws:
java.io.IOException
-
-