diff --git a/src/Contracts/SearchQuery.php b/src/Contracts/SearchQuery.php index 6a9c5fe7..88c7eeee 100644 --- a/src/Contracts/SearchQuery.php +++ b/src/Contracts/SearchQuery.php @@ -29,6 +29,7 @@ class SearchQuery private ?array $attributesToSearchOn = null; private ?bool $showRankingScore = null; private ?bool $showRankingScoreDetails = null; + private ?float $rankingScoreThreshold = null; public function setQuery(string $q): SearchQuery { @@ -130,6 +131,13 @@ public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): Sear return $this; } + public function setRankingScoreThreshold(?float $rankingScoreThreshold): SearchQuery + { + $this->rankingScoreThreshold = $rankingScoreThreshold; + + return $this; + } + public function setSort(array $sort): SearchQuery { $this->sort = $sort; @@ -230,6 +238,7 @@ public function toArray(): array 'attributesToSearchOn' => $this->attributesToSearchOn, 'showRankingScore' => $this->showRankingScore, 'showRankingScoreDetails' => $this->showRankingScoreDetails, + 'rankingScoreThreshold' => $this->rankingScoreThreshold ?? null, ], function ($item) { return null !== $item; }); } } diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index 789d3b23..f695743d 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -763,6 +763,18 @@ public function testSearchWithShowRankingScore(): void self::assertArrayHasKey('_rankingScore', $response->getHits()[0]); } + public function testSearchWithRankingScoreThreshold(): void + { + $response = $this->index->search('the', ['showRankingScore' => true, 'rankingScoreThreshold' => 0.9]); + + self::assertArrayHasKey('_rankingScore', $response->getHits()[0]); + self::assertSame(3, $response->getHitsCount()); + + $response = $this->index->search('the', ['showRankingScore' => true, 'rankingScoreThreshold' => 0.99]); + + self::assertSame(0, $response->getHitsCount()); + } + public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void { $response = $this->index->updateFilterableAttributes(['genre']);