Skip to content

Apache Lucene open-source search software

SOLR-9772: reuse comparator when deriving fieldSortValues

yonik738198ef34b6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 00c0669a9f3..56c491cfd2a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -128,6 +128,9 @@ Optimizations
* SOLR-9726: Reduce number of lookupOrd calls made by the DocValuesFacets.getCounts method.
(Jonny Marks via Christine Poerschke)
+* SOLR-9772: Deriving distributed sort values (fieldSortValues) should reuse
+ comparator and only invalidate leafComparator. (John Call via yonik)
+
Bug Fixes
----------------------
* SOLR-9701: NPE in export handler when "fl" parameter is omitted.
diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
index c0484eca0dc..9823f3d1274 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -616,7 +616,7 @@ public class QueryComponent extends SearchComponent
// :TODO: would be simpler to always serialize every position of SortField[]
if (type==SortField.Type.SCORE || type==SortField.Type.DOC) continue;
- FieldComparator<?> comparator = null;
+ FieldComparator<?> comparator = sortField.getComparator(1,0);
LeafFieldComparator leafComparator = null;
Object[] vals = new Object[nDocs];
@@ -633,13 +633,13 @@ public class QueryComponent extends SearchComponent
idx = ReaderUtil.subIndex(doc, leaves);
currentLeaf = leaves.get(idx);
if (idx != lastIdx) {
- // we switched segments. invalidate comparator.
- comparator = null;
+ // we switched segments. invalidate leafComparator.
+ lastIdx = idx;
+ leafComparator = null;
}
}
- if (comparator == null) {
- comparator = sortField.getComparator(1,0);
+ if (leafComparator == null) {
leafComparator = comparator.getLeafComparator(currentLeaf);
}