pquentin commented on a change in pull request #445: URL: https://github.com/apache/lucene/pull/445#discussion_r751606167
########## 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: Thanks, that fixed it. Now I can run the test 1000 times without any failures. -- 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