Why is ascending geo distance sorting faster than descending geo distance sorting

LatLonDocValuesField.newDistanceSort is a primitive implemented at Lucene level:

The key of the algorithm is on LatLonPointDistanceComparator, the javadocs explain the strategy used. A bounding box from the min competitive distance is built and therefore we can reject points based on this bounding box instead of calculating the distance for every element which is expensive.

1 Like