Skip to content

Apache Lucene open-source search software

SOLR-9726: Reduce number of lookupOrd calls made by the DocValuesFacets.getCounts method. (Jonny Marks via Christine Poerschke)

Christine Poerschkecbf8235e570c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ad022fbf35b..bb49a697127 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -109,6 +109,9 @@ Optimizations
* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
filters specified by using those filters as acceptDocs. (yonik)
+* SOLR-9726: Reduce number of lookupOrd calls made by the DocValuesFacets.getCounts method.
+ (Jonny Marks via Christine Poerschke)
+
Bug Fixes
----------------------
* SOLR-9701: NPE in export handler when "fl" parameter is omitted.
diff --git a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
index 0dab34bf506..3714bf1b9f6 100644
--- a/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
@@ -173,17 +173,18 @@ public class DocValuesFacets {
int min=mincount-1; // the smallest value in the top 'N' values
for (int i=(startTermIndex==-1)?1:0; i<nTerms; i++) {
int c = counts[i];
- if (contains != null) {
- final BytesRef term = si.lookupOrd(startTermIndex+i);
- if (!SimpleFacets.contains(term.utf8ToString(), contains, ignoreCase)) {
- continue;
- }
- }
if (c>min) {
// NOTE: we use c>min rather than c>=min as an optimization because we are going in
// index order, so we already know that the keys are ordered. This can be very
// important if a lot of the counts are repeated (like zero counts would be).
+ if (contains != null) {
+ final BytesRef term = si.lookupOrd(startTermIndex+i);
+ if (!SimpleFacets.contains(term.utf8ToString(), contains, ignoreCase)) {
+ continue;
+ }
+ }
+
// smaller term numbers sort higher, so subtract the term number instead
long pair = (((long)c)<<32) + (Integer.MAX_VALUE - i);
boolean displaced = queue.insert(pair);