This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new b61fdcbbec4 SOLR-17801: Use TotalHitCountCollector to collect count
when no rows needed (#2655)
b61fdcbbec4 is described below
commit b61fdcbbec44332885a08b07f82b0aca56c93df2
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 8300dd5b2b8..9146a0c84ab 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -272,6 +272,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 a2009aff65d..0f0735b66ac 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1895,18 +1895,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() {
@@ -1934,6 +1923,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(