pquentin commented on a change in pull request #445:
URL: https://github.com/apache/lucene/pull/445#discussion_r751102338



##########
File path: 
lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
##########
@@ -206,6 +210,42 @@ public void testFieldExistsButNoDocsHaveField() throws 
IOException {
     dir.close();
   }
 
+  public void testQueryMatchesCount() throws IOException {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+
+    int randomNumDocs = TestUtil.nextInt(random(), 10, 100);
+    int numMatchingDocs = 0;
+
+    for (int i = 0; i < randomNumDocs; i++) {
+      Document doc = new Document();
+      if (random().nextBoolean()) {
+        doc.add(new NumericDocValuesField("f", i));
+        doc.add(new LongPoint("f", i));
+        numMatchingDocs++;
+      }
+      w.addDocument(doc);
+    }
+    w.forceMerge(1);
+
+    DirectoryReader reader = w.getReader();
+    final IndexSearcher searcher = new IndexSearcher(reader);
+
+    Query testQuery = new DocValuesFieldExistsQuery("f");
+    assertEquals(searcher.count(testQuery), numMatchingDocs);
+    final Weight weight = searcher.createWeight(testQuery, ScoreMode.COMPLETE, 
1);
+    assertEquals(weight.count(reader.leaves().get(0)), numMatchingDocs);
+
+    // Test that we can't count in O(1) when there are deleted documents
+    w.deleteDocuments(LongPoint.newRangeQuery("f", 0L, 10L));
+    w.commit();

Review comment:
       Thanks, fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to