This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 7e4af6667e4 SOLR-18016: Fix spatial distance sorting with SRPT and 
filter cache (#3935)
7e4af6667e4 is described below

commit 7e4af6667e40d4c1d40e08f649dee57d99f76d54
Author: David Smiley <[email protected]>
AuthorDate: Wed Dec 10 13:48:33 2025 -0500

    SOLR-18016: Fix spatial distance sorting with SRPT and filter cache (#3935)
    
    SolrIndexSearcher: shouldn't avoid calling LeafCollector.setScorer
    
    Move test
---
 ...rse dist sorting on LatLonPointSpatialField.yml |  5 ++-
 .../org/apache/solr/search/SolrIndexSearcher.java  | 10 ++++-
 .../org/apache/solr/search/TestSolr4Spatial.java   | 44 +++++++++++++++++++++-
 .../org/apache/solr/search/TestSolr4Spatial2.java  | 41 --------------------
 4 files changed, 55 insertions(+), 45 deletions(-)

diff --git a/changelog/unreleased/SOLR-18006-Fix reverse dist sorting on 
LatLonPointSpatialField.yml b/changelog/unreleased/SOLR-18006-Fix reverse dist 
sorting on LatLonPointSpatialField.yml
index d3306164c38..3af69caac4a 100644
--- a/changelog/unreleased/SOLR-18006-Fix reverse dist sorting on 
LatLonPointSpatialField.yml   
+++ b/changelog/unreleased/SOLR-18006-Fix reverse dist sorting on 
LatLonPointSpatialField.yml   
@@ -1,5 +1,4 @@
-# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
-title: Fix reverse distance sorting on LatLonPointSpatialField when combined 
with filter cache
+title: Fix reverse distance sorting on LatLonPointSpatialField and "SRPT" 
fields when combined with the filter cache.  This is a regression since Solr 
9.9.
 type: fixed # added, changed, fixed, deprecated, removed, dependency_update, 
security, other
 authors:
   - name: Jan Høydahl
@@ -10,3 +9,5 @@ authors:
 links:
   - name: SOLR-18006
     url: https://issues.apache.org/jira/browse/SOLR-18006
+  - name: SOLR-18016
+    url: https://issues.apache.org/jira/browse/SOLR-18016
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 3604f84d0fc..7868d7688ca 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -2381,7 +2381,7 @@ public class SolrIndexSearcher extends IndexSearcher 
implements Closeable, SolrI
         base = leaf.docBase;
         end = base + leaf.reader().maxDoc();
         leafCollector = topCollector.getLeafCollector(leaf);
-        // we should never need to set the scorer given the settings for the 
collector
+        leafCollector.setScorer(CONSTANT_SCORABLE);
       }
       leafCollector.collect(doc - base);
     }
@@ -2703,4 +2703,12 @@ public class SolrIndexSearcher extends IndexSearcher 
implements Closeable, SolrI
   public long getWarmupTime() {
     return warmupTime;
   }
+
+  private static final Scorable CONSTANT_SCORABLE =
+      new Scorable() {
+        @Override
+        public float score() throws IOException {
+          return 1f;
+        }
+      };
 }
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java 
b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
index 3aed5e46d5a..01e58f42e77 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
@@ -68,7 +68,7 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    initCore("solrconfig-basic.xml", "schema-spatial.xml");
+    initCore("solrconfig-spatial.xml", "schema-spatial.xml");
   }
 
   @Override
@@ -595,4 +595,46 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {
       assertFalse(strategy.getFieldType().stored());
     }
   }
+
+  @Test
+  public void testSOLR18006_GeodistDescWithFilterQuery() throws Exception { // 
AND SOLR-18016
+    assumeTrue("Test requires distance calculations", canCalcDistance);
+    assumeFalse("Test doesn't work with bbox", isBBoxField(fieldName));
+    // SOLR-18006: geodist() desc sorting causes NPE when spatial query is in 
filter query
+    // Reproduction from JIRA issue with exact coordinates and parameters
+
+    // Index sample documents from JIRA issue
+    assertU(adoc("id", "pt-001", fieldName, "48.106651,11.628476"));
+    assertU(adoc("id", "pt-002", fieldName, "48.113089,11.622016"));
+    assertU(adoc("id", "pt-003", fieldName, "48.137154,11.576124"));
+    assertU(adoc("id", "pt-004", fieldName, "48.135125,11.581981"));
+    assertU(adoc("id", "pt-005", fieldName, "48.121,11.612"));
+    assertU(adoc("id", "pt-006", fieldName, "48.09,11.64"));
+    assertU(commit());
+
+    // Test descending sort with filter query - exact query from JIRA that 
triggers NPE
+    // Expected order by distance DESC from 
pt=48.11308880280511,11.622015740056845:
+    // pt-003 (48.137154,11.576124) - farthest
+    // pt-004 (48.135125,11.581981)
+    // pt-006 (48.09,11.64)
+    // pt-005 (48.121,11.612)
+    // pt-001 (48.106651,11.628476)
+    // pt-002 (48.113089,11.622016) - closest
+    assertJQ(
+        req(
+            "q", "*:*",
+            "fq", "{!geofilt}",
+            "sfield", fieldName,
+            "pt", "48.11308880280511,11.622015740056845",
+            "d", "10",
+            "fl", "id",
+            "sort", "geodist() desc"),
+        "/response/numFound==6",
+        "/response/docs/[0]/id=='pt-003'", // farthest
+        "/response/docs/[1]/id=='pt-004'",
+        "/response/docs/[2]/id=='pt-006'",
+        "/response/docs/[3]/id=='pt-005'",
+        "/response/docs/[4]/id=='pt-001'",
+        "/response/docs/[5]/id=='pt-002'"); // closest
+  }
 }
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java 
b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
index 2c96be7eb2a..166d17e8e94 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
@@ -551,45 +551,4 @@ public class TestSolr4Spatial2 extends SolrTestCaseJ4 {
             "sort", "min(geodist(),geodist(55.4721936,-2.24703,llp)) asc"),
         "/response/docs/[0]/id=='2'");
   }
-
-  @Test
-  public void testSOLR18006_GeodistDescWithFilterQuery() throws Exception {
-    // SOLR-18006: geodist() desc sorting causes NPE when spatial query is in 
filter query
-    // Reproduction from JIRA issue with exact coordinates and parameters
-    String fieldName = "llp_km";
-
-    // Index sample documents from JIRA issue
-    assertU(adoc("id", "pt-001", fieldName, "48.106651,11.628476"));
-    assertU(adoc("id", "pt-002", fieldName, "48.113089,11.622016"));
-    assertU(adoc("id", "pt-003", fieldName, "48.137154,11.576124"));
-    assertU(adoc("id", "pt-004", fieldName, "48.135125,11.581981"));
-    assertU(adoc("id", "pt-005", fieldName, "48.121,11.612"));
-    assertU(adoc("id", "pt-006", fieldName, "48.09,11.64"));
-    assertU(commit());
-
-    // Test descending sort with filter query - exact query from JIRA that 
triggers NPE
-    // Expected order by distance DESC from 
pt=48.11308880280511,11.622015740056845:
-    // pt-003 (48.137154,11.576124) - farthest
-    // pt-004 (48.135125,11.581981)
-    // pt-006 (48.09,11.64)
-    // pt-005 (48.121,11.612)
-    // pt-001 (48.106651,11.628476)
-    // pt-002 (48.113089,11.622016) - closest
-    assertJQ(
-        req(
-            "q", "*:*",
-            "fq", "{!geofilt}",
-            "sfield", fieldName,
-            "pt", "48.11308880280511,11.622015740056845",
-            "d", "10",
-            "fl", "id",
-            "sort", "geodist() desc"),
-        "/response/numFound==6",
-        "/response/docs/[0]/id=='pt-003'", // farthest
-        "/response/docs/[1]/id=='pt-004'",
-        "/response/docs/[2]/id=='pt-006'",
-        "/response/docs/[3]/id=='pt-005'",
-        "/response/docs/[4]/id=='pt-001'",
-        "/response/docs/[5]/id=='pt-002'"); // closest
-  }
 }

Reply via email to