Skip to content

Apache Lucene open-source search software

SOLR-11595: optimize SolrIndexSearcher.collectionStatistics

David Smiley3923e9fba3eb
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fe85f18cbdc..e6034567a7f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -123,6 +123,9 @@ Optimizations
* SOLR-11641: Change `frange` to default to `cost=100` so default behavior is to PostFilter if user specifies
`cache=false` (hossman)
+* SOLR-11595: SolrIndexSearcher.localCollectionStatistics is now faster by leveraging an existing
+ cached MultiFields. Noticeable when many fields are searched. (David Smiley)
+
Other Changes
----------------------
* SOLR-11478: Solr should remove itself from live_nodes in zk immediately on shutdown. (Cao Manh Dat)
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 6a178cb1a91..0e8c0226a4c 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -367,7 +367,15 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
}
public CollectionStatistics localCollectionStatistics(String field) throws IOException {
- return super.collectionStatistics(field);
+ // Could call super.collectionStatistics(field); but we can use a cached MultiTerms
+ assert field != null;
+ // SlowAtomicReader has a cache of MultiTerms
+ Terms terms = getSlowAtomicReader().terms(field);
+ if (terms == null) {
+ return null;
+ }
+ return new CollectionStatistics(field, reader.maxDoc(),
+ terms.getDocCount(), terms.getSumTotalTermFreq(), terms.getSumDocFreq());
}
public boolean isCachingEnabled() {