Respect the submission guidelines above! Drupal.org issue forks cause additional work for the project maintainer!
Setup
- Solr version: 8.11.2
- Drupal Core version: 9.5.10
- Search API version: 8.x-1.29
- Search API Solr version: 4.2.12
- Configured Solr Connector: Basic Auth
Issue
In #3344097: Solarium insists distances be integers and search_api_solr casts them as floats, the radius value for a spatial search was changed to be cast to an integer in order to address a warning caused by an implicit conversion from float, since the Solarium Spatial object expects an integer value for distance.
A question was raised at the time:
Or making the argument that Solarium should support floats?
I think this should be revisited, because as it is, the conversion from floats to ints adds imprecision to the search. For example, assuming the Solr field settings have kilometers configured as the distanceUnits, and the application allows users to search either in miles or kilometers, searching within a 1-mile radius (1.60934 km) will return the result set for 1 km, because casting 1.60934 to int = 1.
In local testing, Solr queries worked correctly with the `d` parameter as a float values in spatial searches.
Suggested Next Steps
- Change
\Solarium\Component\SpatialgetDistance, andsetDistancemethods to set and return distance as float - Cast radius to float instead of int in
\Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::setSpatial()
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3389956-spatial-radius-as-float-4.patch | 867 bytes | godotislate |
Comments
Comment #2
godotislateComment #3
godotislateComment #4
godotislateSearch API PR https://github.com/mkalkbrenner/search_api_solr/pull/95
Patch on GH: https://patch-diff.githubusercontent.com/raw/mkalkbrenner/search_api_sol...
Solarium issue: https://github.com/solariumphp/solarium/issues/1095
Solarium PR https://github.com/solariumphp/solarium/pull/1096 Patch: https://patch-diff.githubusercontent.com/raw/solariumphp/solarium/pull/1...
Comment #5
godotislateComment #6
mkalkbrennerThanks for your work on this!
We should adjust composer.json to require solarium 6.3.3.
And the SearchApiSolrLocationTest should be adjusted to use floats.
Comment #7
godotislateUpdated the PR on Github to bump the Solarium version and adjust the tests. I'm guessing the test will fail until there's a 6.3.3 Solarium release.
Comment #8
mkalkbrennerSolarium 6.3.3 has been released and the PR on github has been merged. Thanks!