Methods Summary |
---|
public java.lang.Object | clone()
CustomScoreQuery clone = (CustomScoreQuery)super.clone();
clone.subQuery = (Query) subQuery.clone();
if (valSrcQuery!=null) {
clone.valSrcQuery = (ValueSourceQuery) valSrcQuery.clone();
}
return clone;
|
protected org.apache.lucene.search.Weight | createWeight(org.apache.lucene.search.Searcher searcher)
return new CustomWeight(searcher);
|
public org.apache.lucene.search.Explanation | customExplain(int doc, org.apache.lucene.search.Explanation subQueryExpl, org.apache.lucene.search.Explanation valSrcExpl)Explain the custom score.
Whenever overriding {@link #customScore(int, float, float)},
this method should also be overriden to provide the correct explanation
for the part of the custom scoring.
float valSrcScore = valSrcExpl==null ? 1 : valSrcExpl.getValue();
Explanation exp = new Explanation( valSrcScore * subQueryExpl.getValue(), "custom score: product of:");
exp.addDetail(subQueryExpl);
if (valSrcExpl != null) {
exp.addDetail(valSrcExpl);
}
return exp;
|
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.
return valSrcScore * subQueryScore;
|
public boolean | equals(java.lang.Object o)Returns true if o is equal to this.
if (getClass() != o.getClass()) {
return false;
}
CustomScoreQuery other = (CustomScoreQuery)o;
return this.getBoost() == other.getBoost()
&& this.subQuery.equals(other.subQuery)
&& (this.valSrcQuery==null ? other.valSrcQuery==null
: this.valSrcQuery.equals(other.valSrcQuery));
|
public void | extractTerms(java.util.Set terms)
subQuery.extractTerms(terms);
if (valSrcQuery!=null) {
valSrcQuery.extractTerms(terms);
}
|
public int | hashCode()Returns a hash code value for this object.
int valSrcHash = valSrcQuery==null ? 0 : valSrcQuery.hashCode();
return (getClass().hashCode() + subQuery.hashCode() + valSrcHash) ^ Float.floatToIntBits(getBoost());
|
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.
return strict;
|
public java.lang.String | name()A short name of this query, used in {@link #toString(String)}.
return "custom";
|
public org.apache.lucene.search.Query | rewrite(org.apache.lucene.index.IndexReader reader)
subQuery = subQuery.rewrite(reader);
if (valSrcQuery!=null) {
valSrcQuery = (ValueSourceQuery) valSrcQuery.rewrite(reader);
}
return this;
|
public void | setStrict(boolean strict)Set the strict mode of this query.
this.strict = strict;
|
public java.lang.String | toString(java.lang.String field)
StringBuffer sb = new StringBuffer(name()).append("(");
sb.append(subQuery.toString(field));
if (valSrcQuery!=null) {
sb.append(", ").append(valSrcQuery.toString(field));
}
sb.append(")");
sb.append(strict?" STRICT" : "");
return sb.toString() + ToStringUtils.boost(getBoost());
|