Skip to content

Commit 751f665

Browse files
added rankingScoreThreshold
1 parent bfae87b commit 751f665

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/search.rs

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

339-
#[serde(skip_serializing_if = "Option::is_none")]
340-
pub(crate) index_uid: Option<&'a str>,
341339

342340
///Defines one attribute in the filterableAttributes list as a distinct attribute.
343341
#[serde(skip_serializing_if = "Option::is_none")]
344-
pub(crate) distinct: Option<&'a str>,
342+
pub distinct: Option<&'a str>,
343+
344+
#[serde(skip_serializing_if = "Option::is_none")]
345+
pub ranking_score_threshold: Option<f64>,
346+
347+
#[serde(skip_serializing_if = "Option::is_none")]
348+
pub(crate) index_uid: Option<&'a str>,
349+
345350
}
346351

347352
#[allow(missing_docs)]
@@ -372,6 +377,7 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
372377
matching_strategy: None,
373378
index_uid: None,
374379
distinct: None,
380+
ranking_score_threshold: None,
375381
}
376382
}
377383
pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a, Http> {
@@ -567,6 +573,10 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
567573
pub fn with_distinct<'b>(&'b mut self, distinct: &'a str) -> &'b mut SearchQuery<'a, Http> {
568574
self.distinct = Some(distinct);
569575
self
576+
}
577+
pub fn with_ranking_score_threshold<'b>(&'b mut self, ranking_score_threshold: f64) -> &'b mut SearchQuery<'a, Http> {
578+
self.ranking_score_threshold = Some(ranking_score_threshold);
579+
self
570580
}
571581
pub fn build(&mut self) -> SearchQuery<'a, Http> {
572582
self.clone()
@@ -1134,6 +1144,21 @@ mod tests {
11341144
Ok(())
11351145
}
11361146

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

0 commit comments

Comments
 (0)