Skip to content

Commit

Permalink
Merge #598
Browse files Browse the repository at this point in the history
598: Add frequency to matchingStrategy r=irevoire a=NoodleSamaChan

# Pull Request

## Related issue
Fixes #594

## What does this PR do?
Fixes #594
I also corrected a small typo in the test for LAST

## 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 fafebbf + c86db69 commit 3d15605
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,15 @@ search_parameter_guide_matching_strategy_2: |-
.execute()
.await
.unwrap();
search_parameter_guide_matching_strategy_3: |-
let results: SearchResults<Movie> = client
.index("movies")
.search()
.with_query("white shirt")
.with_matching_strategy(MatchingStrategies::FREQUENCY)
.execute()
.await
.unwrap();
search_parameter_guide_hitsperpage_1: |-
client.index("movies").search().with_hits_per_page(15).execute().await?;
search_parameter_guide_page_1: |-
Expand Down
19 changes: 18 additions & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum MatchingStrategies {
ALL,
#[serde(rename = "last")]
LAST,
#[serde(rename = "frequency")]
FREQUENCY,
}

/// A single result.
Expand Down Expand Up @@ -1151,7 +1153,7 @@ mod tests {
}

#[meilisearch_test]
async fn test_matching_strategy_left(client: Client, index: Index) -> Result<(), Error> {
async fn test_matching_strategy_last(client: Client, index: Index) -> Result<(), Error> {
setup_test_index(&client, &index).await?;

let results = SearchQuery::new(&index)
Expand All @@ -1165,6 +1167,21 @@ mod tests {
Ok(())
}

#[meilisearch_test]
async fn test_matching_strategy_frequency(client: Client, index: Index) -> Result<(), Error> {
setup_test_index(&client, &index).await?;

let results = SearchQuery::new(&index)
.with_query("Harry Styles")
.with_matching_strategy(MatchingStrategies::FREQUENCY)
.execute::<Document>()
.await
.unwrap();

assert_eq!(results.hits.len(), 7);
Ok(())
}

#[meilisearch_test]
async fn test_generate_tenant_token_from_client(
client: Client,
Expand Down

0 comments on commit 3d15605

Please sign in to comment.