[ 
https://issues.apache.org/jira/browse/SOLR-18016?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18043887#comment-18043887
 ] 

David Smiley commented on SOLR-18016:
-------------------------------------

I have some WIP to test & fix.  The identical test of the previous issue, just 
changing the field name, reproduces the issue.  JTS is unrelated.  I believe 
the root cause/fix, is that Solr should be setting a Scorer on the 
LeafCollector 
[here|https://github.com/apache/solr/blob/ee1198804ff39fad2d5886883991b724e77bd625/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java#L2401],
 even though Yonik wrote a comment in 2009 saying it was unnecessary.  Maybe 
it's typically not necessary, but it's possibly necessary.  An arrangement of 
circumstances since Lucene 9.12 led to a specific implementation of 
LeafCollector coming out of Lucene DoubleValuesSource that Solr hasn't been 
using very much if at all, since Solr mostly uses the legacy ValueSource 
implementations.  I don't even think the underlying issue is spatial related, 
but that is where we're starting to see more of the new DoubleValuesSource 
being used.  And we didn't yet have a realistic test -- one with the filter 
cache enabled.  Ideally that recent test that was added would rotate through 
all the field types, not just the specific one field that exposed an issue.

I'll work on improvements / fix.

> NPE when distance sorting on SpatialRecursivePrefixTreeFieldType
> ----------------------------------------------------------------
>
>                 Key: SOLR-18016
>                 URL: https://issues.apache.org/jira/browse/SOLR-18016
>             Project: Solr
>          Issue Type: Bug
>          Components: search
>    Affects Versions: 9.9, 9.10
>            Reporter: Umut Saribiyik
>            Assignee: David Smiley
>            Priority: Major
>         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}
> *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