javanna commented on a change in pull request #612:
URL: https://github.com/apache/lucene/pull/612#discussion_r791517659
##########
File path:
lucene/core/src/java/org/apache/lucene/search/TotalHitCountCollector.java
##########
@@ -16,7 +16,11 @@
*/
package org.apache.lucene.search;
-/** Just counts the total number of hits. */
+/**
+ * Just counts the total number of hits. For cases when this is the only
collector used, {@link
+ * IndexSearcher#count(Query)} can be called instead of {@link
IndexSearcher#search(Query,
+ * Collector)} which will automatically create an instance of this collector
internally
Review comment:
definitely, I had misread the collector used by count, I will clarify.
##########
File path: lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java
##########
@@ -91,16 +91,12 @@ public void
testCreateWeightDoesNotSeekIfScoresAreNotNeeded() throws IOException
IndexSearcher searcher = new IndexSearcher(reader);
// use a collector rather than searcher.count() which would just read the
// doc freq instead of creating a scorer
- TotalHitCountCollector collector = new TotalHitCountCollector();
- searcher.search(query, collector);
- assertEquals(1, collector.getTotalHits());
+ assertEquals(1, searcher.count(query));
Review comment:
oh boy I did not notice the comment which said exactly that :)
##########
File path: lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
##########
@@ -945,7 +945,7 @@ public void onUse(Query query) {
searcher.setQueryCache(queryCache);
searcher.setQueryCachingPolicy(policy);
- searcher.search(query.build(), new TotalHitCountCollector());
+ searcher.count(query.build());
Review comment:
yes, I missed reverting it, thanks!
##########
File path: lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
##########
@@ -1169,7 +1169,7 @@ public void testDetectMutatedQueries() throws IOException
{
searcher.setQueryCachingPolicy(ALWAYS_CACHE);
BadQuery query = new BadQuery();
- searcher.count(query);
+ searcher.search(query, new TotalHitCountCollector());
Review comment:
looks like this was already using count, I guess I should revert this
bit? I meant to revert the other usage above but I got confused.
##########
File path:
lucene/core/src/java/org/apache/lucene/search/TotalHitCountCollector.java
##########
@@ -16,7 +16,12 @@
*/
package org.apache.lucene.search;
-/** Just counts the total number of hits. */
+/**
+ * Just counts the total number of hits. For cases when this is the only
collector used, {@link
+ * IndexSearcher#count(Query)} should be called instead of {@link
IndexSearcher#search(Query,
+ * Collector)} as the former is faster whenever the match can be returned
directly from the index
Review comment:
I meant match count, but count is fine too.
##########
File path: lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
##########
@@ -1169,7 +1169,7 @@ public void testDetectMutatedQueries() throws IOException
{
searcher.setQueryCachingPolicy(ALWAYS_CACHE);
BadQuery query = new BadQuery();
- searcher.count(query);
+ searcher.search(query, new TotalHitCountCollector());
Review comment:
great then
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]