diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e9cece39645..59627be4bb6 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -115,6 +115,9 @@ Optimizations * LUCENE-4317: Improve reuse of internal TokenStreams and StringReader in oal.document.Field. (Uwe Schindler, Chris Male, Robert Muir) +* LUCENE-4327: Support out-of-order scoring in FilteredQuery for higher + performance. (Mike McCandless, Robert Muir) + Build * LUCENE-3985: Upgrade to randomizedtesting 2.0.0. Added support for diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java index 9ea088f7ed0..0423cf45a88 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.List; import org.apache.lucene.index.AtomicReaderContext; -import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery.BooleanWeight; /* Description from Doug Cutting (excerpted from @@ -115,7 +114,7 @@ final class BooleanScorer extends Scorer { // Therefore the only methods that are implemented are score() and doc(). private static final class BucketScorer extends Scorer { - float score; + double score; int doc = NO_MORE_DOCS; int freq; @@ -134,13 +133,13 @@ final class BooleanScorer extends Scorer { public int nextDoc() { return NO_MORE_DOCS; } @Override - public float score() { return score; } + public float score() { return (float)score; } } static final class Bucket { int doc = -1; // tells if bucket is valid - float score; // incremental score + double score; // incremental score // TODO: break out bool anyProhibited, int // numRequiredMatched; then we can remove 32 limit on // required clauses diff --git a/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java index f22ab894241..2f37693fe06 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java @@ -129,6 +129,7 @@ class ConjunctionScorer extends Scorer { @Override public float score() throws IOException { + // TODO: sum into a double and cast to float if we ever send required clauses to BS1 float sum = 0.0f; for (int i = 0; i < scorers.length; i++) { sum += scorers[i].score(); diff --git a/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java b/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java index 5db1e03b066..bf547bda361 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java @@ -90,6 +90,7 @@ class ConjunctionTermScorer extends Scorer { @Override public float score() throws IOException { + // TODO: sum into a double and cast to float if we ever send required clauses to BS1 float sum = 0.0f; for (DocsAndFreqs docs : docsAndFreqs) { sum += docs.scorer.score(); diff --git a/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java b/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java index e2302f974f3..9dd68a5ed83 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java @@ -83,9 +83,7 @@ public class FilteredQuery extends Query { @Override public boolean scoresDocsOutOfOrder() { - // TODO: Support out-of-order scoring! - // For now we return false here, as we always get the scorer in order - return false; + return true; } @Override @@ -148,9 +146,7 @@ public class FilteredQuery extends Query { if (useRandomAccess) { // if we are using random access, we return the inner scorer, just with other acceptDocs - // TODO, replace this by when BooleanWeight is fixed to be consistent with its scorer implementations: - // return weight.scorer(context, scoreDocsInOrder, topScorer, filterAcceptDocs); - return weight.scorer(context, true, topScorer, filterAcceptDocs); + return weight.scorer(context, scoreDocsInOrder, topScorer, filterAcceptDocs); } else { assert firstFilterDoc > -1; // we are gonna advance() this scorer, so we set inorder=true/toplevel=false diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java index d9839634911..b20dc1e36ed 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java @@ -69,6 +69,7 @@ class ReqOptSumScorer extends Scorer { */ @Override public float score() throws IOException { + // TODO: sum into a double and cast to float if we ever send required clauses to BS1 int curDoc = reqScorer.docID(); float reqScore = reqScorer.score(); if (optScorer == null) {