Skip to content

Commit 3f00031

Browse files
Merge #601
601: Support ranking score threshold r=irevoire a=NoodleSamaChan # Pull Request ## Related issue Fixes #593 ## What does this PR do? fixes #593 and removed a slight typo from former PR (distinct option) ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: NoodleSamaChan <[email protected]>
2 parents bfae87b + 9f500ac commit 3f00031

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

.code-samples.meilisearch.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,3 +1730,12 @@ distinct_attribute_guide_distinct_parameter_1: |-
17301730
.execute()
17311731
.await
17321732
.unwrap();
1733+
search_parameter_reference_ranking_score_threshold_1: |-
1734+
let res = client
1735+
.index("INDEX_NAME")
1736+
.search()
1737+
.with_query("badman")
1738+
.with_ranking_score_threshold(0.2)
1739+
.execute()
1740+
.await
1741+
.unwrap();

src/search.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,16 @@ pub struct SearchQuery<'a, Http: HttpClient> {
336336
#[serde(skip_serializing_if = "Option::is_none")]
337337
pub matching_strategy: Option<MatchingStrategies>,
338338

339+
///Defines one attribute in the filterableAttributes list as a distinct attribute.
339340
#[serde(skip_serializing_if = "Option::is_none")]
340-
pub(crate) index_uid: Option<&'a str>,
341+
pub distinct: Option<&'a str>,
341342

342-
///Defines one attribute in the filterableAttributes list as a distinct attribute.
343+
///Excludes results below the specified ranking score.
343344
#[serde(skip_serializing_if = "Option::is_none")]
344-
pub(crate) distinct: Option<&'a str>,
345+
pub ranking_score_threshold: Option<f64>,
346+
347+
#[serde(skip_serializing_if = "Option::is_none")]
348+
pub(crate) index_uid: Option<&'a str>,
345349
}
346350

347351
#[allow(missing_docs)]
@@ -372,6 +376,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
372376
matching_strategy: None,
373377
index_uid: None,
374378
distinct: None,
379+
ranking_score_threshold: None,
375380
}
376381
}
377382
pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a, Http> {
@@ -568,6 +573,13 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
568573
self.distinct = Some(distinct);
569574
self
570575
}
576+
pub fn with_ranking_score_threshold<'b>(
577+
&'b mut self,
578+
ranking_score_threshold: f64,
579+
) -> &'b mut SearchQuery<'a, Http> {
580+
self.ranking_score_threshold = Some(ranking_score_threshold);
581+
self
582+
}
571583
pub fn build(&mut self) -> SearchQuery<'a, Http> {
572584
self.clone()
573585
}
@@ -1134,6 +1146,21 @@ mod tests {
11341146
Ok(())
11351147
}
11361148

1149+
#[meilisearch_test]
1150+
async fn test_query_show_ranking_score_threshold(
1151+
client: Client,
1152+
index: Index,
1153+
) -> Result<(), Error> {
1154+
setup_test_index(&client, &index).await?;
1155+
1156+
let mut query = SearchQuery::new(&index);
1157+
query.with_query("dolor text");
1158+
query.with_ranking_score_threshold(1.0);
1159+
let results: SearchResults<Document> = index.execute_query(&query).await.unwrap();
1160+
assert!(results.hits.is_empty());
1161+
Ok(())
1162+
}
1163+
11371164
#[meilisearch_test]
11381165
async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> {
11391166
setup_test_index(&client, &index).await?;

0 commit comments

Comments
 (0)