Class CustomScoreQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.function.CustomScoreQuery
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class CustomScoreQuery extends Query
Query that sets document score as a programmatic function of several (sub) scores.- the score of its subQuery (any query)
- (optional) the score of its ValueSourtceQuery (or queries),
for most simple/convineient use case this query would be a
FieldScoreQuery
customScore(int, float, float).WARNING: The status of the search.function package is experimental. The APIs introduced here might change in the future and will not be supported anymore in such a case.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description CustomScoreQuery(Query subQuery)Create a CustomScoreQuery over input subQuery.CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)Create a CustomScoreQuery over input subQuery and aValueSourceQuery.CustomScoreQuery(Query subQuery, ValueSourceQuery[] valSrcQueries)Create a CustomScoreQuery over input subQuery and aValueSourceQuery.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Objectclone()Returns a clone of this query.ExplanationcustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)Explain the custom score.ExplanationcustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)Explain the custom score.floatcustomScore(int doc, float subQueryScore, float valSrcScore)Compute a custom score by the subQuery score and the ValueSourceQuery score.floatcustomScore(int doc, float subQueryScore, float[] valSrcScores)Compute a custom score by the subQuery score and a number of ValueSourceQuery scores.booleanequals(java.lang.Object o)Returns true ifois equal to this.voidextractTerms(java.util.Set terms)Expert: adds all terms occuring in this query to the terms set.inthashCode()Returns a hash code value for this object.booleanisStrict()Checks if this is strict custom scoring.java.lang.Stringname()A short name of this query, used intoString(String).Queryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.voidsetStrict(boolean strict)Set the strict mode of this query.java.lang.StringtoString(java.lang.String field)Prints a query to a string, withfieldassumed to be the default field and omitted.-
Methods inherited from class org.apache.lucene.search.Query
combine, getBoost, getSimilarity, mergeBooleanQueries, setBoost, toString, weight
-
-
-
-
Constructor Detail
-
CustomScoreQuery
public CustomScoreQuery(Query subQuery)
Create a CustomScoreQuery over input subQuery.- Parameters:
subQuery- the sub query whose scored is being customed. Must not be null.
-
CustomScoreQuery
public CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)
Create a CustomScoreQuery over input subQuery and aValueSourceQuery.- Parameters:
subQuery- the sub query whose score is being customed. Must not be null.valSrcQuery- a value source query whose scores are used in the custom score computation. For most simple/convineient use case this would be aFieldScoreQuery. This parameter is optional - it can be null.
-
CustomScoreQuery
public CustomScoreQuery(Query subQuery, ValueSourceQuery[] valSrcQueries)
Create a CustomScoreQuery over input subQuery and aValueSourceQuery.- Parameters:
subQuery- the sub query whose score is being customed. Must not be null.valSrcQueries- value source queries whose scores are used in the custom score computation. For most simple/convineient use case these would beFieldScoreQueries. This parameter is optional - it can be null or even an empty array.
-
-
Method Detail
-
rewrite
public Query rewrite(IndexReader reader) throws java.io.IOException
Description copied from class:QueryExpert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
-
extractTerms
public void extractTerms(java.util.Set terms)
Description copied from class:QueryExpert: adds all terms occuring in this query to the terms set. Only works if this query is in itsrewrittenform.- Overrides:
extractTermsin classQuery
-
clone
public java.lang.Object clone()
Description copied from class:QueryReturns a clone of this query.
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted.The representation used is one that is supposed to be readable by
QueryParser. However, there are the following limitations:- If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
- Some of the more complicated queries (e.g. span queries) don't have a representation that can be parsed by QueryParser.
-
equals
public boolean equals(java.lang.Object o)
Returns true ifois equal to this.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Returns a hash code value for this object.- Overrides:
hashCodein classjava.lang.Object
-
customScore
public float customScore(int doc, float subQueryScore, float[] valSrcScores)Compute a custom score by the subQuery score and a number of ValueSourceQuery 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 ValueSourceQueries is always < 2 it is sufficient to override the other
costomScore()method, which is simpler.The default computation herein is:
ModifiedScore = valSrcScore * subQueryScore[0] * subQueryScore[1] * ...- Parameters:
doc- id of scored doc.subQueryScore- score of that doc by the subQuery.valSrcScores- score of that doc by the ValueSourceQuery.- Returns:
- custom score.
-
customScore
public float customScore(int doc, float subQueryScore, float valSrcScore)Compute a custom score by the subQuery score and the ValueSourceQuery 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 ValueSourceQueries is always < 2 it is sufficient to override this costomScore() method, which is simpler.
The default computation herein is:
ModifiedScore = valSrcScore * subQueryScore- Parameters:
doc- id of scored doc.subQueryScore- score of that doc by the subQuery.valSrcScore- score of that doc by the ValueSourceQuery.- Returns:
- custom score.
-
customExplain
public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
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
-
customExplain
public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
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
-
isStrict
public boolean isStrict()
Checks if this is strict custom scoring. In strict custom scoring, the ValueSource part of does not participate in weight normalization. This may be useful when one wants full control over how scores are modified, and does not care about normalizing by the ValueSource part. One particular case where this is useful if for testing this query.Note: only has effect when the ValueSource part is not null.
-
setStrict
public void setStrict(boolean strict)
Set the strict mode of this query.- Parameters:
strict- The strict mode to set.- See Also:
isStrict()
-
name
public java.lang.String name()
A short name of this query, used intoString(String).
-
-
DataMelt 3.0 © DataMelt by jWork.ORG