Skip to content

Commit b61fdcb

Browse files
authored
SOLR-17801: Use TotalHitCountCollector to collect count when no rows needed (#2655)
1 parent aa435e1 commit b61fdcb

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ Optimizations
272272

273273
* SOLR-17775: Speed up function queries in 'fl' param. (Yura Korolov)
274274

275+
* SOLR-17801: Use TotalHitCountCollector to collect count when no rows needed (Kevin Risden)
276+
275277
Bug Fixes
276278
---------------------
277279
* SOLR-17629: If SQLHandler failed to open the underlying stream (e.g. Solr returns an error; could be user/syntax problem),

solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,18 +1895,7 @@ private void getDocListNC(QueryResult qr, QueryCommand cmd) throws IOException {
18951895
final Collector collector;
18961896

18971897
if (!needScores) {
1898-
collector =
1899-
new SimpleCollector() {
1900-
@Override
1901-
public void collect(int doc) {
1902-
numHits[0]++;
1903-
}
1904-
1905-
@Override
1906-
public ScoreMode scoreMode() {
1907-
return ScoreMode.COMPLETE_NO_SCORES;
1908-
}
1909-
};
1898+
collector = new TotalHitCountCollector();
19101899
} else {
19111900
collector =
19121901
new SimpleCollector() {
@@ -1934,6 +1923,11 @@ public ScoreMode scoreMode() {
19341923
buildAndRunCollectorChain(qr, query, collector, cmd, pf.postFilter);
19351924

19361925
totalHits = numHits[0];
1926+
if (collector instanceof TotalHitCountCollector) {
1927+
totalHits = ((TotalHitCountCollector) collector).getTotalHits();
1928+
} else {
1929+
totalHits = numHits[0];
1930+
}
19371931
maxScore = totalHits > 0 ? topscore[0] : 0.0f;
19381932
docList =
19391933
new DocSlice(

0 commit comments

Comments
 (0)