Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 54 additions & 2 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -234,6 +242,10 @@ pub struct SearchQuery<'a> {
/// Default: `false`
#[serde(skip_serializing_if = "Option::is_none")]
pub show_matches_position: Option<bool>,

/// Defines the strategy on how to handle queries containing multiple words.
#[serde(skip_serializing_if = "Option::is_none")]
pub matching_strategy: Option<MatchingStrategies>,
}

#[allow(missing_docs)]
Expand All @@ -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> {
Expand All @@ -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
}
Expand Down Expand Up @@ -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<T: 'static + DeserializeOwned>(
&'a self,
Expand Down Expand Up @@ -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::<Document>()
.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::<Document>()
.await
.unwrap();

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

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