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

  1. Change \Solarium\Component\Spatial getDistance, and setDistance methods to set and return distance as float
  2. Cast radius to float instead of int in \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::setSpatial()

Comments

godotislate created an issue. See original summary.

godotislate’s picture

Issue summary: View changes
godotislate’s picture

Issue summary: View changes
godotislate’s picture

Status: Active » Needs review
mkalkbrenner’s picture

Status: Needs review » Needs work

Thanks 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.

godotislate’s picture

Status: Needs work » Needs review

Updated 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.

mkalkbrenner’s picture

Status: Needs review » Fixed

Solarium 6.3.3 has been released and the PR on github has been merged. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.