jpountz commented on a change in pull request #445: URL: https://github.com/apache/lucene/pull/445#discussion_r751199436
########## 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: Since this query is supposed to match documents that have doc values, we need to index doc values too. ```suggestion doc.add(new NumericDocValuesfield("long", i)); doc.add(new StringField("string", "value", Store.NO)); doc.add(new SortedDocValuesField("string", new BytesRef("value")); ``` ########## 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)); + 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); Review comment: Can you also test the case when a field doesn't exist? -- 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