jpountz commented on a change in pull request #622: URL: https://github.com/apache/lucene/pull/622#discussion_r791841541
########## File path: lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java ########## @@ -167,19 +168,36 @@ public void run() { RandomPicks.randomFrom( random(), new String[] {"blue", "red", "yellow", "green"}); final Query q = new TermQuery(new Term("color", value)); - TotalHitCountCollector collector = new TotalHitCountCollector(); - searcher.search(q, collector); // will use the cache - final int totalHits1 = collector.getTotalHits(); - TotalHitCountCollector collector2 = new TotalHitCountCollector(); - searcher.search( - q, - new FilterCollector(collector2) { - @Override - public ScoreMode scoreMode() { - return ScoreMode.COMPLETE; // will not use the cache because of scores - } - }); - final long totalHits2 = collector2.getTotalHits(); + TotalHitCountCollectorManager collectorManager = + new TotalHitCountCollectorManager(); + final int totalHits1 = + searcher.search(q, collectorManager); // will use the cache + final long totalHits2 = + searcher.search( + q, + new CollectorManager<FilterCollector, Integer>() { + @Override + public FilterCollector newCollector() { + return new FilterCollector(new TotalHitCountCollector()) { + @Override + public ScoreMode scoreMode() { + return ScoreMode + .COMPLETE; // will not use the cache because of scores Review comment: maybe put the comment on the previous line so that the formatter doesn't do this ########## File path: lucene/core/src/java/org/apache/lucene/search/TotalHitCountCollectorManager.java ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.io.IOException; +import java.util.Collection; + +/** + * Collector manager based on {@link TotalHitCountCollector} that allows users to parallelize + * counting the number of hits. + */ +public class TotalHitCountCollectorManager Review comment: Should it live in the test framework since it's only used by tests? ########## File path: lucene/misc/src/test/org/apache/lucene/misc/search/TestDocValuesStatsCollector.java ########## @@ -396,10 +394,8 @@ public void testDocsWithSortedSetValues() throws IOException { try (DirectoryReader reader = DirectoryReader.open(indexWriter)) { IndexSearcher searcher = new IndexSearcher(reader); SortedSetDocValuesStats stats = new SortedSetDocValuesStats(field); - TotalHitCountCollector totalHitCount = new TotalHitCountCollector(); - searcher.search( - new MatchAllDocsQuery(), - MultiCollector.wrap(totalHitCount, new DocValuesStatsCollector(stats))); + + searcher.search(new MatchAllDocsQuery(), new DocValuesStatsCollector(stats)); Review comment: Hmm good question. I think so, but would like @gsmiller to confirm. ########## File path: lucene/misc/src/test/org/apache/lucene/misc/search/TestMemoryAccountingBitsetCollector.java ########## @@ -64,14 +62,12 @@ public void testMemoryAccountingBitsetCollectorMemoryLimit() { CollectorMemoryTracker tracker = new CollectorMemoryTracker("testMemoryTracker", perCollectorMemoryLimit); MemoryAccountingBitsetCollector bitSetCollector = new MemoryAccountingBitsetCollector(tracker); - TotalHitCountCollector hitCountCollector = new TotalHitCountCollector(); IndexSearcher searcher = new IndexSearcher(reader); expectThrows( IllegalStateException.class, () -> { - searcher.search( - new MatchAllDocsQuery(), MultiCollector.wrap(hitCountCollector, bitSetCollector)); + searcher.search(new MatchAllDocsQuery(), bitSetCollector); Review comment: I'm pretty sure this one is ok. ########## File path: lucene/core/src/java/org/apache/lucene/search/TotalHitCountCollectorManager.java ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.io.IOException; +import java.util.Collection; + +/** + * Collector manager based on {@link TotalHitCountCollector} that allows users to parallelize + * counting the number of hits. + */ +public class TotalHitCountCollectorManager Review comment: Then maybe we should add a comment about the fact that `IndexSearcher#count` is preferred as it performs faster and that this TotalHitCountCollectorManager only makes sense if wrapped inside of a MultiCollectorManager? -- 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