This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new b63e64c7a9c SOLR-17801: Use TotalHitCountCollector to collect count
when no rows needed (#2655)
b63e64c7a9c is described below
commit b63e64c7a9c19d144fb206f483e3592832b6b6fa
Author: Kevin Risden <[email protected]>
AuthorDate: Mon Jun 30 09:32:46 2025 -0400
SOLR-17801: Use TotalHitCountCollector to collect count when no rows needed
(#2655)
---
solr/CHANGES.txt | 2 ++
.../java/org/apache/solr/search/SolrIndexSearcher.java | 18 ++++++------------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 41080a1d73c..5bfd78565b0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -81,6 +81,8 @@ Optimizations
* SOLR-17775: Speed up function queries in 'fl' param. (Yura Korolov)
+* SOLR-17801: Use TotalHitCountCollector to collect count when no rows needed
(Kevin Risden)
+
Bug Fixes
---------------------
* SOLR-17629: If SQLHandler failed to open the underlying stream (e.g. Solr
returns an error; could be user/syntax problem),
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index db3da0b9ae4..f4d0304ec35 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1910,18 +1910,7 @@ public class SolrIndexSearcher extends IndexSearcher
implements Closeable, SolrI
final Collector collector;
if (!needScores) {
- collector =
- new SimpleCollector() {
- @Override
- public void collect(int doc) {
- numHits[0]++;
- }
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
- };
+ collector = new TotalHitCountCollector();
} else {
collector =
new SimpleCollector() {
@@ -1949,6 +1938,11 @@ public class SolrIndexSearcher extends IndexSearcher
implements Closeable, SolrI
buildAndRunCollectorChain(qr, query, collector, cmd, pf.postFilter);
totalHits = numHits[0];
+ if (collector instanceof TotalHitCountCollector) {
+ totalHits = ((TotalHitCountCollector) collector).getTotalHits();
+ } else {
+ totalHits = numHits[0];
+ }
maxScore = totalHits > 0 ? topscore[0] : 0.0f;
docList =
new DocSlice(