File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ' ]);
You can’t perform that action at this time.
0 commit comments