Skip to content

Commit bd1f46a

Browse files
authored
Merge branch 'bump-meilisearch-v1.9.0' into bump-meilisearch-v1.9.0
2 parents 7e95ffb + 9645ddf commit bd1f46a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Contracts/SearchQuery.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SearchQuery
2929
private ?array $attributesToSearchOn = null;
3030
private ?bool $showRankingScore = null;
3131
private ?bool $showRankingScoreDetails = null;
32+
private ?float $rankingScoreThreshold = null;
3233

3334
public function setQuery(string $q): SearchQuery
3435
{
@@ -130,6 +131,13 @@ public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): Sear
130131
return $this;
131132
}
132133

134+
public function setRankingScoreThreshold(?float $rankingScoreThreshold): SearchQuery
135+
{
136+
$this->rankingScoreThreshold = $rankingScoreThreshold;
137+
138+
return $this;
139+
}
140+
133141
public function setSort(array $sort): SearchQuery
134142
{
135143
$this->sort = $sort;
@@ -230,6 +238,7 @@ public function toArray(): array
230238
'attributesToSearchOn' => $this->attributesToSearchOn,
231239
'showRankingScore' => $this->showRankingScore,
232240
'showRankingScoreDetails' => $this->showRankingScoreDetails,
241+
'rankingScoreThreshold' => $this->rankingScoreThreshold ?? null,
233242
], function ($item) { return null !== $item; });
234243
}
235244
}

tests/Endpoints/SearchTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,18 @@ public function testSearchWithShowRankingScore(): void
763763
self::assertArrayHasKey('_rankingScore', $response->getHits()[0]);
764764
}
765765

766+
public function testSearchWithRankingScoreThreshold(): void
767+
{
768+
$response = $this->index->search('the', ['showRankingScore' => true, 'rankingScoreThreshold' => 0.9]);
769+
770+
self::assertArrayHasKey('_rankingScore', $response->getHits()[0]);
771+
self::assertSame(3, $response->getHitsCount());
772+
773+
$response = $this->index->search('the', ['showRankingScore' => true, 'rankingScoreThreshold' => 0.99]);
774+
775+
self::assertSame(0, $response->getHitsCount());
776+
}
777+
766778
public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void
767779
{
768780
$response = $this->index->updateFilterableAttributes(['genre']);

0 commit comments

Comments
 (0)