Package org.apache.lucene.queries
Class CustomScoreQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.queries.CustomScoreQuery
- All Implemented Interfaces:
Cloneable
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
FunctionQuery(or queries).
getCustomScoreProvider(org.apache.lucene.index.AtomicReaderContext).-
Constructor Summary
ConstructorsConstructorDescriptionCustomScoreQuery(Query subQuery) Create a CustomScoreQuery over input subQuery.CustomScoreQuery(Query subQuery, FunctionQuery scoringQuery) Create a CustomScoreQuery over input subQuery and aFunctionQuery.CustomScoreQuery(Query subQuery, FunctionQuery... scoringQueries) Create a CustomScoreQuery over input subQuery and aFunctionQuery. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a clone of this query.createWeight(IndexSearcher searcher) Expert: Constructs an appropriate Weight implementation for this query.booleanReturns true ifois equal to this.voidextractTerms(Set<Term> terms) Expert: adds all terms occurring in this query to the terms set.Query[]The scoring queries that only affect the score of CustomScoreQuery.The sub-query that CustomScoreQuery wraps, affecting both the score and which documents match.inthashCode()Returns a hash code value for this object.booleanisStrict()Checks if this is strict custom scoring.name()A short name of this query, used intoString(String).rewrite(IndexReader reader) Expert: called to re-write queries into primitive queries.voidsetStrict(boolean strict) Set the strict mode of this query.Prints a query to a string, withfieldassumed to be the default field and omitted.
-
Constructor Details
-
CustomScoreQuery
Create a CustomScoreQuery over input subQuery.- Parameters:
subQuery- the sub query whose scored is being customized. Must not be null.
-
CustomScoreQuery
Create a CustomScoreQuery over input subQuery and aFunctionQuery.- Parameters:
subQuery- the sub query whose score is being customized. Must not be null.scoringQuery- a value source query whose scores are used in the custom score computation. This parameter is optional - it can be null.
-
CustomScoreQuery
Create a CustomScoreQuery over input subQuery and aFunctionQuery.- Parameters:
subQuery- the sub query whose score is being customized. Must not be null.scoringQueries- value source queries whose scores are used in the custom score computation. This parameter is optional - it can be null or even an empty array.
-
-
Method Details
-
rewrite
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.- Overrides:
rewritein classQuery- Throws:
IOException
-
extractTerms
Description copied from class:QueryExpert: adds all terms occurring in this query to the terms set. Only works if this query is in itsrewrittenform.- Overrides:
extractTermsin classQuery
-
clone
Description copied from class:QueryReturns a clone of this query. -
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
equals
Returns true ifois equal to this. -
hashCode
public int hashCode()Returns a hash code value for this object. -
createWeight
Description copied from class:QueryExpert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeightin classQuery- Throws:
IOException
-
isStrict
public boolean isStrict()Checks if this is strict custom scoring. In strict custom scoring, theValueSourcepart 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 theValueSourcepart. One particular case where this is useful if for testing this query.Note: only has effect when the
ValueSourcepart 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:
-
getSubQuery
The sub-query that CustomScoreQuery wraps, affecting both the score and which documents match. -
getScoringQueries
The scoring queries that only affect the score of CustomScoreQuery. -
name
A short name of this query, used intoString(String).
-