diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index e2997571..7fbea501 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -1730,3 +1730,12 @@ distinct_attribute_guide_distinct_parameter_1: |- .execute() .await .unwrap(); +search_parameter_reference_ranking_score_threshold_1: |- + let res = client + .index("INDEX_NAME") + .search() + .with_query("badman") + .with_ranking_score_threshold(0.2) + .execute() + .await + .unwrap(); diff --git a/src/search.rs b/src/search.rs index f56c86b0..73272202 100644 --- a/src/search.rs +++ b/src/search.rs @@ -336,12 +336,16 @@ pub struct SearchQuery<'a, Http: HttpClient> { #[serde(skip_serializing_if = "Option::is_none")] pub matching_strategy: Option, + ///Defines one attribute in the filterableAttributes list as a distinct attribute. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) index_uid: Option<&'a str>, + pub distinct: Option<&'a str>, - ///Defines one attribute in the filterableAttributes list as a distinct attribute. + ///Excludes results below the specified ranking score. #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) distinct: Option<&'a str>, + pub ranking_score_threshold: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) index_uid: Option<&'a str>, } #[allow(missing_docs)] @@ -372,6 +376,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> { matching_strategy: None, index_uid: None, distinct: None, + ranking_score_threshold: None, } } 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> { self.distinct = Some(distinct); self } + pub fn with_ranking_score_threshold<'b>( + &'b mut self, + ranking_score_threshold: f64, + ) -> &'b mut SearchQuery<'a, Http> { + self.ranking_score_threshold = Some(ranking_score_threshold); + self + } pub fn build(&mut self) -> SearchQuery<'a, Http> { self.clone() } @@ -1134,6 +1146,21 @@ mod tests { Ok(()) } + #[meilisearch_test] + async fn test_query_show_ranking_score_threshold( + client: Client, + index: Index, + ) -> Result<(), Error> { + setup_test_index(&client, &index).await?; + + let mut query = SearchQuery::new(&index); + query.with_query("dolor text"); + query.with_ranking_score_threshold(1.0); + let results: SearchResults = index.execute_query(&query).await.unwrap(); + assert!(results.hits.is_empty()); + Ok(()) + } + #[meilisearch_test] async fn test_phrase_search(client: Client, index: Index) -> Result<(), Error> { setup_test_index(&client, &index).await?;