diff --git a/README.md b/README.md index 7ce91876..545c180e 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi ## 🤖 Compatibility with Meilisearch -This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0). +This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0). ## ⚙️ Development Workflow and Contributing diff --git a/README.tpl b/README.tpl index 75f37900..11df60cb 100644 --- a/README.tpl +++ b/README.tpl @@ -106,7 +106,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi ## 🤖 Compatibility with Meilisearch -This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0). +This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0). ## ⚙️ Development Workflow and Contributing diff --git a/src/search.rs b/src/search.rs index a0b7c713..a2f0abb3 100644 --- a/src/search.rs +++ b/src/search.rs @@ -9,6 +9,14 @@ pub struct MatchRange { pub length: usize, } +#[derive(Debug, Clone, Serialize)] +pub enum MatchingStrategies { + #[serde(rename = "all")] + ALL, + #[serde(rename = "last")] + LAST, +} + /// A single result. /// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches. #[derive(Deserialize, Debug)] @@ -234,6 +242,10 @@ pub struct SearchQuery<'a> { /// Default: `false` #[serde(skip_serializing_if = "Option::is_none")] pub show_matches_position: Option, + + /// Defines the strategy on how to handle queries containing multiple words. + #[serde(skip_serializing_if = "Option::is_none")] + pub matching_strategy: Option, } #[allow(missing_docs)] @@ -255,6 +267,7 @@ impl<'a> SearchQuery<'a> { highlight_pre_tag: None, highlight_post_tag: None, show_matches_position: None, + matching_strategy: None, } } pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a> { @@ -274,7 +287,10 @@ impl<'a> SearchQuery<'a> { self.filter = Some(filter); self } - pub fn with_facets<'b>(&'b mut self, facets: Selectors<&'a [&'a str]>) -> &'b mut SearchQuery<'a> { + pub fn with_facets<'b>( + &'b mut self, + facets: Selectors<&'a [&'a str]>, + ) -> &'b mut SearchQuery<'a> { self.facets = Some(facets); self } @@ -332,10 +348,16 @@ impl<'a> SearchQuery<'a> { self.show_matches_position = Some(show_matches_position); self } + pub fn with_matching_strategy<'b>( + &'b mut self, + matching_strategy: MatchingStrategies, + ) -> &'b mut SearchQuery<'a> { + self.matching_strategy = Some(matching_strategy); + self + } pub fn build(&mut self) -> SearchQuery<'a> { self.clone() } - /// Execute the query and fetch the results. pub async fn execute( &'a self, @@ -755,6 +777,36 @@ mod tests { Ok(()) } + #[meilisearch_test] + async fn test_matching_strategy_all(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::ALL) + .execute::() + .await + .unwrap(); + + assert_eq!(results.hits.len(), 0); + Ok(()) + } + + #[meilisearch_test] + async fn test_matching_strategy_left(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::LAST) + .execute::() + .await + .unwrap(); + + assert_eq!(results.hits.len(), 7); + Ok(()) + } + #[meilisearch_test] async fn test_generate_tenant_token_from_client( client: Client,