Umut Saribiyik created SOLR-18016:
-------------------------------------

             Summary: issue with distance sorting on 
SpatialRecursivePrefixTreeFieldType with spatialContextFactory JTS in Solr 9.9 
/ 9.10
                 Key: SOLR-18016
                 URL: https://issues.apache.org/jira/browse/SOLR-18016
             Project: Solr
          Issue Type: Bug
          Components: search
    Affects Versions: 9.10, 9.9
            Reporter: Umut Saribiyik
         Attachments: image-2025-12-05-16-20-48-202.png

*Summary*
Sorting exception for {{SpatialRecursivePrefixTreeFieldType}} when using 
{{spatialContextFactory="JTS". }}Identical to SOLR-18006 but for a different 
field type.

*Description*
Hello [~janhoy] [~dsmiley] 

an issue identical to *SOLR-18006* occurs when using the field type 
*{{SpatialRecursivePrefixTreeFieldType}}* with 
{{{}*spatialContextFactory="JTS"*{}}}.
Both sorting directions ({{{}asc{}}} and {{{}desc{}}}) result in the same 
exception, which worked before solr 9.9 and 9.10

I was able to reproduce this on {*}main{*}, by extending the existing 
{{TestSolr4Spatial2}} class with an additional test.
----
h2. *Steps to Reproduce*
h3. *1. Add JTS dependency*

Extend {{{}build.gradle{}}}:

 
{code:java}
implementation("org.locationtech.jts:jts-core:1.20.0") {code}
 
h3. *2. Disable dependency locking (for local testing only)*

In {{{}dependencies.gradle{}}}, comment out:
{code:java}
// lockAllConfigurations(){code}
(This is required only locally to avoid blocking the JTS dependency.){{{}{}}}
h3. *3. Extend schema with additional field type and field*

Add to {{{}schema-spatial.xml{}}}:

 

 
{code:java}
...
<fieldType name="location_jts" class="solr.SpatialRecursivePrefixTreeFieldType" 
geo="true" maxDistErr="0.001" spatialContextFactory="JTS" distErrPct="0.025" 
distanceUnits="kilometers"/>
...
<field name="location_jts" type="location_jts" uninvertible="true" 
multiValued="false" indexed="true" stored="true"/>{code}
 
h3. *4. Add and run the test*

 

 
{code:java}
@Test
public void 
test_geodist_on_SpatialRecursivePrefixTreeFieldType_with_jts_spatialContextFactory()
 throws Exception {

  String fieldName = "location_jts";

  // Index sample documents
  assertU(adoc("id", "jts-001", fieldName, "11.628476,48.106651"));
  assertU(adoc("id", "jts-002", fieldName, "11.622016,48.113089"));
  assertU(adoc("id", "jts-003", fieldName, "11.576124,48.137154"));
  assertU(adoc("id", "jts-004", fieldName, "11.581981,48.135125"));
  assertU(adoc("id", "jts-005", fieldName, "11.612,48.121"));
  assertU(adoc("id", "jts-006", fieldName, "11.64,48.09"));
  assertU(commit());


  assertJQ(
      req(
          "q", "*:*",
          "fq", "{!geofilt}",
          "sfield", fieldName,
          "pt", "11.622015740056845,48.11308880280511",
          "d", "1000",
          "fl", "id",
          "sort", "geodist() desc"), // Or 'geodist() asc'
      "/response/numFound==6",
      "/response/docs/[0]/id=='jts-003'", // farthest
      "/response/docs/[1]/id=='jts-004'",
      "/response/docs/[2]/id=='jts-006'",
      "/response/docs/[3]/id=='jts-005'",
      "/response/docs/[4]/id=='jts-001'",
      "/response/docs/[5]/id=='jts-002'"); // closest
}{code}
 

 

Test Result:

!image-2025-12-05-16-20-48-202.png!
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to