From 0e1d7698c39b54168040391589cd86597ca2df5e Mon Sep 17 00:00:00 2001 From: Edward Wu Date: Wed, 27 Sep 2023 23:24:45 -0700 Subject: [PATCH] Issue #1095: Spatial component should use floats for distance. (#1096) --- CHANGELOG.md | 4 ++++ src/Component/Spatial.php | 8 ++++---- tests/Component/RequestBuilder/SpatialTest.php | 4 ++-- tests/Component/SpatialTest.php | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da61c04bd..f606f570f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the Solarium library will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Changed +- Spatial component distance type changed from int to float + ## [6.3.2] ### Added - Solarium\Component\ReRankQuery::setOperator() diff --git a/src/Component/Spatial.php b/src/Component/Spatial.php index a514d5f66..f0b841f3d 100644 --- a/src/Component/Spatial.php +++ b/src/Component/Spatial.php @@ -52,11 +52,11 @@ public function setField(string $sfield): self } /** - * @param int $distance + * @param float $distance * * @return self Provides fluent interface */ - public function setDistance(int $distance): self + public function setDistance(float $distance): self { $this->setOption('d', $distance); @@ -89,9 +89,9 @@ public function getField(): ?string /** * Get d option. * - * @return int|null + * @return float|null */ - public function getDistance(): ?int + public function getDistance(): ?float { return $this->getOption('d'); } diff --git a/tests/Component/RequestBuilder/SpatialTest.php b/tests/Component/RequestBuilder/SpatialTest.php index 0b48635dc..277d20aa9 100644 --- a/tests/Component/RequestBuilder/SpatialTest.php +++ b/tests/Component/RequestBuilder/SpatialTest.php @@ -16,7 +16,7 @@ public function testBuildComponent() $component = new Component(); $component->setField('geo'); - $component->setDistance(50); + $component->setDistance(50.1415); $component->setPoint('48.2233,16.3161'); $request = $builder->buildComponent($component, $request); @@ -25,7 +25,7 @@ public function testBuildComponent() [ 'pt' => '48.2233,16.3161', 'sfield' => 'geo', - 'd' => 50, + 'd' => 50.1415, ], $request->getParams() ); diff --git a/tests/Component/SpatialTest.php b/tests/Component/SpatialTest.php index b4edae779..cce372912 100644 --- a/tests/Component/SpatialTest.php +++ b/tests/Component/SpatialTest.php @@ -22,7 +22,7 @@ public function testConfigMode() { $options = [ 'sfield' => 'geo', - 'd' => 50, + 'd' => 50.1415, 'pt' => '48.2233,16.3161', ]; @@ -64,7 +64,7 @@ public function testSetAndGetField() public function testSetAndGetDistance() { - $value = 5; + $value = 5.9438; $this->spatial->setDistance($value); $this->assertEquals($value, $this->spatial->getDistance());