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



##########
File path: 
lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
##########
@@ -206,6 +210,52 @@ 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 LongPoint("long", i));
+        doc.add(new NumericDocValuesfield("long", i));
+        doc.add(new StringField("string", "value", Store.NO));
+        doc.add(new SortedDocValuesField("string", new BytesRef("value"));
+        numMatchingDocs++;
+      }
+      w.addDocument(doc);
+    }
+    w.forceMerge(1);
+
+    DirectoryReader reader = w.getReader();
+    final IndexSearcher searcher = new IndexSearcher(reader);
+
+    assertSameCount(reader, searcher, "long", numMatchingDocs);
+    assertSameCount(reader, searcher, "string", numMatchingDocs);
+
+    // Test that we can't count in O(1) when there are deleted documents
+    w.deleteDocuments(LongPoint.newRangeQuery("long", 0L, 10L));
+    DirectoryReader reader2 = w.getReader();
+    final IndexSearcher searcher2 = new IndexSearcher(reader2);
+    final Query testQuery = new DocValuesFieldExistsQuery("long");
+    final Weight weight2 = searcher2.createWeight(testQuery, 
ScoreMode.COMPLETE, 1);
+    assertEquals(weight2.count(reader2.leaves().get(0)), -1);

Review comment:
       I suspect that it's because the test picks a merge policy that decides 
that the index has too many deletions and that the segment should get 
rewritten.You could do `w.w.getConfig().setMergePolicy(NoMergePolicy.INSTANCE)` 
after the `forcemerge` to prevent the call to `deleteTerms` from triggering a 
merge.

##########
File path: 
lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
##########
@@ -206,6 +210,50 @@ 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 LongPoint("long", i));
+        doc.add(new StringField("string", "value", Store.NO));

Review comment:
       Year this made me wonder if we should update your new count impl to do 
this:
   
   ```
   if (fieldInfo == null || fieldInfo.getDocValuesType() == DocValuesType.NONE) 
{
     return 0; // the field doesn't index doc values
   }
   ```




-- 
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