Skip to content

Add frequency to matchingStrategy #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading