org.apache.lucene.search.function

Class CustomScoreQuery

public class CustomScoreQuery extends Query

Query that sets document score as a programmatic function of (up to) two (sub) scores.
  1. the score of its subQuery (any query)
  2. (optional) the score of its ValueSourtceQuery, for most simple/convineient use case this query would be a FieldScoreQuery
Subclasses can modify the computation by overriding CustomScoreQuery.

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 Summary
CustomScoreQuery(Query subQuery)
Create a CustomScoreQuery over input subQuery.
CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)
Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.
Method Summary
Objectclone()
protected WeightcreateWeight(Searcher searcher)
ExplanationcustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
Explain the custom score.
floatcustomScore(int doc, float subQueryScore, float valSrcScore)
Compute a custom score by the subQuery score and the ValueSourceQuery score.
booleanequals(Object o)
Returns true if o is equal to this.
voidextractTerms(Set terms)
inthashCode()
Returns a hash code value for this object.
booleanisStrict()
Checks if this is strict custom scoring.
Stringname()
A short name of this query, used in toString.
Queryrewrite(IndexReader reader)
voidsetStrict(boolean strict)
Set the strict mode of this query.
StringtoString(String field)

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 a ValueSourceQuery.

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 a FieldScoreQuery. This parameter is optional - it can be null.

Method Detail

clone

public Object clone()

createWeight

protected Weight createWeight(Searcher searcher)

customExplain

public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
Explain the custom score. Whenever overriding CustomScoreQuery, this method should also be overriden 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

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.

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.

equals

public boolean equals(Object o)
Returns true if o is equal to this.

extractTerms

public void extractTerms(Set terms)

hashCode

public int hashCode()
Returns a hash code value for this object.

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.

name

public String name()
A short name of this query, used in toString.

rewrite

public Query rewrite(IndexReader reader)

setStrict

public void setStrict(boolean strict)
Set the strict mode of this query.

Parameters: strict The strict mode to set.

See Also: isStrict

toString

public String toString(String field)
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.