janhoy commented on code in PR #3923:
URL: https://github.com/apache/solr/pull/3923#discussion_r2591042441
##########
solr/core/src/java/org/apache/solr/schema/LatLonPointSpatialField.java:
##########
@@ -311,11 +309,27 @@ public String toString() {
@Override
public SortField getSortField(boolean reverse) {
+ // Use the optimized Lucene distance sort
+ SortField distanceSort =
+ LatLonDocValuesField.newDistanceSort(fieldName, queryPoint.getY(),
queryPoint.getX());
+
+ // If descending, we need to wrap it to reverse the sort order
+ // Note: We can't just use super.getSortField(true) because that uses
a different code path
+ // that doesn't work correctly with the spatial filter query context
if (reverse) {
- return super.getSortField(true); // will use an impl that calls
getValues
+ // Create a reverse sort field that delegates to the distance sort
comparator
+ return new SortField(distanceSort.getField(),
distanceSort.getType(), true) {
+ @Override
+ public FieldComparator<?> getComparator(int numHits, Pruning
pruning) {
+ // Get the base comparator (for ascending order)
+ @SuppressWarnings("unchecked")
+ FieldComparator<Double> baseComparator =
+ (FieldComparator<Double>)
distanceSort.getComparator(numHits, pruning);
+ return baseComparator;
+ }
+ };
Review Comment:
Well, the fix works. It may not be implementing reverse in the comparator
itself, but when setting `reverse=true` in SortField *will* actually cause a
reverse sort when SortField is applied.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]