Skip to content

Commit

Permalink
Merge #601
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and NoodleSamaChan authored Jul 2, 2024
2 parents bfae87b + 9f500ac commit 3f00031
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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();
33 changes: 30 additions & 3 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,16 @@ pub struct SearchQuery<'a, Http: HttpClient> {
#[serde(skip_serializing_if = "Option::is_none")]
pub matching_strategy: Option<MatchingStrategies>,

///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<f64>,

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

#[allow(missing_docs)]
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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<Document> = 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?;
Expand Down

0 comments on commit 3f00031

Please sign in to comment.