jfreden commented on code in PR #13036: URL: https://github.com/apache/lucene/pull/13036#discussion_r1474087852
########## lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java: ########## @@ -962,6 +962,46 @@ public void testDisjunctionMatchesCount() throws IOException { dir.close(); } + public void testTwoClauseTermDisjunctionCountOptimization() throws Exception { + List<String[]> docContent = + Arrays.asList( + new String[] {"A", "B"}, + new String[] {"A"}, + new String[] {}, + new String[] {"A", "B", "C"}, + new String[] {"B"}, + new String[] {"B", "C"}); + + try (Directory dir = newDirectory()) { + try (IndexWriter w = + new IndexWriter(dir, newIndexWriterConfig().setMergePolicy(newLogMergePolicy()))) { + + for (String[] values : docContent) { + Document doc = new Document(); + for (String value : values) { + doc.add(new StringField("foo", value, Field.Store.NO)); + } + w.addDocument(doc); + } + w.forceMerge(1); + } + + try (IndexReader reader = DirectoryReader.open(dir)) { + IndexSearcher searcher = newSearcher(reader); + + Query query = + new BooleanQuery.Builder() + .add(new TermQuery(new Term("foo", "A")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term("foo", "B")), BooleanClause.Occur.SHOULD) + .setMinimumNumberShouldMatch(1) + .build(); + + int count = searcher.count(query); + assertEquals(5, count); Review Comment: Thank you! Added tests for that and also implemented a `countingIndexSearcher` that overrides `count` to make sure the recursion that is triggered by the optimization happens. -- 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