Index: src/java/org/apache/lucene/search/MatchAllDocsQuery.java =================================================================== --- src/java/org/apache/lucene/search/MatchAllDocsQuery.java (revision 307170) +++ src/java/org/apache/lucene/search/MatchAllDocsQuery.java (working copy) @@ -24,6 +24,8 @@ import org.apache.lucene.search.Similarity; import org.apache.lucene.search.Weight; +import java.io.IOException; + /** * A query that matches all documents. * @@ -36,26 +38,25 @@ private class MatchAllScorer extends Scorer { - IndexReader reader; + final IndexReader reader; int count; - int maxDoc; + final int maxDoc; + final float score; - MatchAllScorer(IndexReader reader, Similarity similarity) { + MatchAllScorer(IndexReader reader, Similarity similarity, Weight w) { super(similarity); this.reader = reader; count = -1; maxDoc = reader.maxDoc(); + score = w.getValue(); } - public int doc() { - return count; + public Explanation explain(int doc) { + return null; // not called... see MatchAllDocsWeight.explain() } - public Explanation explain(int doc) { - Explanation explanation = new Explanation(); - explanation.setValue(1.0f); - explanation.setDescription("MatchAllDocsQuery"); - return explanation; + public int doc() { + return count; } public boolean next() { @@ -81,6 +82,8 @@ private class MatchAllDocsWeight implements Weight { private Searcher searcher; + private float queryWeight; + private float queryNorm; public MatchAllDocsWeight(Searcher searcher) { this.searcher = searcher; @@ -95,29 +98,32 @@ } public float getValue() { - return 1.0f; + return queryWeight; } public float sumOfSquaredWeights() { - return 1.0f; + queryWeight = getBoost(); + return queryWeight * queryWeight; } public void normalize(float queryNorm) { + this.queryNorm = queryNorm; + queryWeight *= this.queryNorm; } 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) { // explain query weight Explanation queryExpl = new Explanation(); - queryExpl.setDescription("MatchAllDocsQuery:"); - - Explanation boostExpl = new Explanation(getBoost(), "boost"); - if (getBoost() != 1.0f) - queryExpl.addDetail(boostExpl); - queryExpl.setValue(boostExpl.getValue()); + queryExpl.setDescription("MatchAllDocsQuery, product of:"); + queryExpl.setValue(getValue()); + if (getBoost() != 1.0f) { + queryExpl.addDetail(new Explanation(getBoost(),"boost")); + } + queryExpl.addDetail(new Explanation(queryNorm,"queryNorm")); return queryExpl; }