mirror of https://github.com/apache/lucene.git
fix score to include boost and query normalization: LUCENE-450
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@358089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a08af8e73d
commit
c86207379d
|
@ -37,32 +37,31 @@ public class MatchAllDocsQuery extends Query {
|
||||||
|
|
||||||
private class MatchAllScorer extends Scorer {
|
private class MatchAllScorer extends Scorer {
|
||||||
|
|
||||||
IndexReader reader;
|
final IndexReader reader;
|
||||||
int count;
|
int id;
|
||||||
int maxDoc;
|
final int maxId;
|
||||||
|
final float score;
|
||||||
|
|
||||||
MatchAllScorer(IndexReader reader, Similarity similarity) {
|
MatchAllScorer(IndexReader reader, Similarity similarity, Weight w) {
|
||||||
super(similarity);
|
super(similarity);
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
count = -1;
|
id = -1;
|
||||||
maxDoc = reader.maxDoc();
|
maxId = reader.maxDoc() - 1;
|
||||||
}
|
score = w.getValue();
|
||||||
|
|
||||||
public int doc() {
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Explanation explain(int doc) {
|
public Explanation explain(int doc) {
|
||||||
Explanation explanation = new Explanation();
|
return null; // not called... see MatchAllDocsWeight.explain()
|
||||||
explanation.setValue(1.0f);
|
}
|
||||||
explanation.setDescription("MatchAllDocsQuery");
|
|
||||||
return explanation;
|
public int doc() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean next() {
|
public boolean next() {
|
||||||
while (count < (maxDoc - 1)) {
|
while (id < maxId) {
|
||||||
count++;
|
id++;
|
||||||
if (!reader.isDeleted(count)) {
|
if (!reader.isDeleted(id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,11 +69,11 @@ public class MatchAllDocsQuery extends Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float score() {
|
public float score() {
|
||||||
return 1.0f;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean skipTo(int target) {
|
public boolean skipTo(int target) {
|
||||||
count = target - 1;
|
id = target - 1;
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +81,8 @@ public class MatchAllDocsQuery extends Query {
|
||||||
|
|
||||||
private class MatchAllDocsWeight implements Weight {
|
private class MatchAllDocsWeight implements Weight {
|
||||||
private Searcher searcher;
|
private Searcher searcher;
|
||||||
|
private float queryWeight;
|
||||||
|
private float queryNorm;
|
||||||
|
|
||||||
public MatchAllDocsWeight(Searcher searcher) {
|
public MatchAllDocsWeight(Searcher searcher) {
|
||||||
this.searcher = searcher;
|
this.searcher = searcher;
|
||||||
|
@ -96,29 +97,32 @@ public class MatchAllDocsQuery extends Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getValue() {
|
public float getValue() {
|
||||||
return 1.0f;
|
return queryWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float sumOfSquaredWeights() {
|
public float sumOfSquaredWeights() {
|
||||||
return 1.0f;
|
queryWeight = getBoost();
|
||||||
|
return queryWeight * queryWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void normalize(float queryNorm) {
|
public void normalize(float queryNorm) {
|
||||||
|
this.queryNorm = queryNorm;
|
||||||
|
queryWeight *= this.queryNorm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scorer scorer(IndexReader reader) {
|
public Scorer scorer(IndexReader reader) {
|
||||||
return new MatchAllScorer(reader, getSimilarity(searcher));
|
return new MatchAllScorer(reader, getSimilarity(searcher), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Explanation explain(IndexReader reader, int doc) {
|
public Explanation explain(IndexReader reader, int doc) {
|
||||||
// explain query weight
|
// explain query weight
|
||||||
Explanation queryExpl = new Explanation();
|
Explanation queryExpl = new Explanation();
|
||||||
queryExpl.setDescription("MatchAllDocsQuery:");
|
queryExpl.setDescription("MatchAllDocsQuery, product of:");
|
||||||
|
queryExpl.setValue(getValue());
|
||||||
Explanation boostExpl = new Explanation(getBoost(), "boost");
|
if (getBoost() != 1.0f) {
|
||||||
if (getBoost() != 1.0f)
|
queryExpl.addDetail(new Explanation(getBoost(),"boost"));
|
||||||
queryExpl.addDetail(boostExpl);
|
}
|
||||||
queryExpl.setValue(boostExpl.getValue());
|
queryExpl.addDetail(new Explanation(queryNorm,"queryNorm"));
|
||||||
|
|
||||||
return queryExpl;
|
return queryExpl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue