Skip to content

Commit

Permalink
Merge #325
Browse files Browse the repository at this point in the history
325: Changes related to the next Meilisearch release (v0.29.0) r=bidoubiwa a=meili-bot

Related to this issue: meilisearch/integration-guides#211

This PR:
- gathers the changes related to the next Meilisearch release (v0.29.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.29.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.29.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._


Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 3, 2022
2 parents 89d3f4a + f84631b commit 66f6b6a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
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

0 comments on commit 66f6b6a

Please sign in to comment.