public class CustomScoreQuery extends Query
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.
Constructor and Description |
---|
CustomScoreQuery(Query subQuery)
Create a CustomScoreQuery over input subQuery.
|
CustomScoreQuery(Query subQuery,
ValueSourceQuery valSrcQuery)
Create a CustomScoreQuery over input subQuery and a
ValueSourceQuery . |
CustomScoreQuery(Query subQuery,
ValueSourceQuery[] valSrcQueries)
Create a CustomScoreQuery over input subQuery and a
ValueSourceQuery . |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a clone of this query.
|
protected Weight |
createWeight(Searcher searcher)
Expert: Constructs an appropriate Weight implementation for this query.
|
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 the ValueSourceQuery score.
|
float |
customScore(int doc,
float subQueryScore,
float[] valSrcScores)
Compute a custom score by the subQuery score and a number of
ValueSourceQuery scores.
|
boolean |
equals(java.lang.Object o)
Returns true if
o is equal to this. |
void |
extractTerms(java.util.Set terms)
Expert: adds all terms occuring in this query to the terms set.
|
int |
hashCode()
Returns a hash code value for this object.
|
boolean |
isStrict()
Checks if this is strict custom scoring.
|
java.lang.String |
name()
A short name of this query, used in
toString(String) . |
Query |
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
|
void |
setStrict(boolean strict)
Set the strict mode of this query.
|
java.lang.String |
toString(java.lang.String field)
Prints a query to a string, with
field assumed to be the
default field and omitted. |
combine, getBoost, getSimilarity, mergeBooleanQueries, setBoost, toString, weight
public CustomScoreQuery(Query subQuery)
subQuery
- the sub query whose scored is being customed. Must not be null.public CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)
ValueSourceQuery
.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 a
FieldScoreQuery
.
This parameter is optional - it can be null.public CustomScoreQuery(Query subQuery, ValueSourceQuery[] valSrcQueries)
ValueSourceQuery
.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 be
FieldScoreQueries
.
This parameter is optional - it can be null or even an empty array.public Query rewrite(IndexReader reader) throws java.io.IOException
Query
public void extractTerms(java.util.Set terms)
Query
rewritten
form.extractTerms
in class Query
public java.lang.Object clone()
Query
public java.lang.String toString(java.lang.String field)
Query
field
assumed 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:
public boolean equals(java.lang.Object o)
o
is equal to this.equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public float customScore(int doc, float subQueryScore, float[] valSrcScores)
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] * ...
doc
- id of scored doc.subQueryScore
- score of that doc by the subQuery.valSrcScores
- score of that doc by the ValueSourceQuery.public float customScore(int doc, float subQueryScore, float valSrcScore)
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
doc
- id of scored doc.subQueryScore
- score of that doc by the subQuery.valSrcScore
- score of that doc by the ValueSourceQuery.public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
customScore(int, float, float[])
,
this method should also be overridden to provide the correct explanation
for the part of the custom scoring.doc
- doc being explained.subQueryExpl
- explanation for the sub-query part.valSrcExpls
- explanation for the value source part.public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
customScore(int, float, float)
,
this method should also be overridden to provide the correct explanation
for the part of the custom scoring.doc
- doc being explained.subQueryExpl
- explanation for the sub-query part.valSrcExpl
- explanation for the value source part.protected Weight createWeight(Searcher searcher) throws java.io.IOException
Query
Only implemented by primitive queries, which re-write to themselves.
createWeight
in class Query
java.io.IOException
public boolean isStrict()
Note: only has effect when the ValueSource part is not null.
public void setStrict(boolean strict)
strict
- The strict mode to set.isStrict()
public java.lang.String name()
toString(String)
.Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.