lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject lucene-solr:master: LUCENE-8607: MatchAllDocsQuery can skip counting hits
Date Thu, 13 Dec 2018 09:19:25 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 42f13731b -> fa025e1f7


LUCENE-8607: MatchAllDocsQuery can skip counting hits


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/fa025e1f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/fa025e1f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/fa025e1f

Branch: refs/heads/master
Commit: fa025e1f78786c57130399acb61fdd81092835f6
Parents: 42f1373
Author: Alan Woodward <romseygeek@apache.org>
Authored: Thu Dec 13 09:01:49 2018 +0000
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Thu Dec 13 09:01:49 2018 +0000

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../apache/lucene/search/MatchAllDocsQuery.java |  4 +++-
 .../lucene/search/TestMatchAllDocsQuery.java    | 23 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/fa025e1f/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b4c7ca5..d6276aa 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -220,6 +220,9 @@ Optimizations
   to early terminate the iterator if the minimum score is greater than the constant
   score. (Christophe Bismuth via Jim Ferenczi)
 
+* LUCENE-8607: MatchAllDocsQuery can shortcut when total hit count is not
+  required (Alan Woodward, Adrien Grand)
+
 ======================= Lucene 7.7.0 =======================
 
 Build

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/fa025e1f/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
index 826494e..80e8d32 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
@@ -24,7 +24,6 @@ import org.apache.lucene.util.Bits;
 
 /**
  * A query that matches all documents.
- *
  */
 public final class MatchAllDocsQuery extends Query {
 
@@ -47,6 +46,9 @@ public final class MatchAllDocsQuery extends Query {
 
       @Override
       public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
+        if (scoreMode == ScoreMode.TOP_SCORES) {
+          return super.bulkScorer(context);
+        }
         final float score = score();
         final int maxDoc = context.reader().maxDoc();
         return new BulkScorer() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/fa025e1f/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
index ee02eed..a2e794e 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
@@ -99,4 +99,27 @@ public class TestMatchAllDocsQuery extends LuceneTestCase {
     iw.addDocument(doc);
   }
 
+  public void testEarlyTermination() throws IOException {
+
+    Directory dir = newDirectory();
+    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(analyzer).setMaxBufferedDocs(2).setMergePolicy(newLogMergePolicy()));
+    for (int i = 0; i < 500; i++) {
+      addDoc("doc" + i, iw);
+    }
+    IndexReader ir = DirectoryReader.open(iw);
+
+    IndexSearcher is = newSearcher(ir);
+
+    final int totalHitsThreshold = 200;
+    TopScoreDocCollector c = TopScoreDocCollector.create(10, null, totalHitsThreshold);
+
+    is.search(new MatchAllDocsQuery(), c);
+    assertEquals(totalHitsThreshold, c.totalHits);
+
+    iw.close();
+    ir.close();
+    dir.close();
+
+  }
+
 }


Mime
View raw message