Skip to content

Commit 66f6b6a

Browse files
bors[bot]meili-botbidoubiwa
authored
Merge #325
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 <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents 89d3f4a + f84631b commit 66f6b6a

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
251251

252252
## 🤖 Compatibility with Meilisearch
253253

254-
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
254+
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
255255

256256
## ⚙️ Development Workflow and Contributing
257257

README.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
106106

107107
## 🤖 Compatibility with Meilisearch
108108

109-
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
109+
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
110110

111111
## ⚙️ Development Workflow and Contributing
112112

src/search.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ pub struct MatchRange {
99
pub length: usize,
1010
}
1111

12+
#[derive(Debug, Clone, Serialize)]
13+
pub enum MatchingStrategies {
14+
#[serde(rename = "all")]
15+
ALL,
16+
#[serde(rename = "last")]
17+
LAST,
18+
}
19+
1220
/// A single result.
1321
/// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches.
1422
#[derive(Deserialize, Debug)]
@@ -234,6 +242,10 @@ pub struct SearchQuery<'a> {
234242
/// Default: `false`
235243
#[serde(skip_serializing_if = "Option::is_none")]
236244
pub show_matches_position: Option<bool>,
245+
246+
/// Defines the strategy on how to handle queries containing multiple words.
247+
#[serde(skip_serializing_if = "Option::is_none")]
248+
pub matching_strategy: Option<MatchingStrategies>,
237249
}
238250

239251
#[allow(missing_docs)]
@@ -255,6 +267,7 @@ impl<'a> SearchQuery<'a> {
255267
highlight_pre_tag: None,
256268
highlight_post_tag: None,
257269
show_matches_position: None,
270+
matching_strategy: None,
258271
}
259272
}
260273
pub fn with_query<'b>(&'b mut self, query: &'a str) -> &'b mut SearchQuery<'a> {
@@ -274,7 +287,10 @@ impl<'a> SearchQuery<'a> {
274287
self.filter = Some(filter);
275288
self
276289
}
277-
pub fn with_facets<'b>(&'b mut self, facets: Selectors<&'a [&'a str]>) -> &'b mut SearchQuery<'a> {
290+
pub fn with_facets<'b>(
291+
&'b mut self,
292+
facets: Selectors<&'a [&'a str]>,
293+
) -> &'b mut SearchQuery<'a> {
278294
self.facets = Some(facets);
279295
self
280296
}
@@ -332,10 +348,16 @@ impl<'a> SearchQuery<'a> {
332348
self.show_matches_position = Some(show_matches_position);
333349
self
334350
}
351+
pub fn with_matching_strategy<'b>(
352+
&'b mut self,
353+
matching_strategy: MatchingStrategies,
354+
) -> &'b mut SearchQuery<'a> {
355+
self.matching_strategy = Some(matching_strategy);
356+
self
357+
}
335358
pub fn build(&mut self) -> SearchQuery<'a> {
336359
self.clone()
337360
}
338-
339361
/// Execute the query and fetch the results.
340362
pub async fn execute<T: 'static + DeserializeOwned>(
341363
&'a self,
@@ -755,6 +777,36 @@ mod tests {
755777
Ok(())
756778
}
757779

780+
#[meilisearch_test]
781+
async fn test_matching_strategy_all(client: Client, index: Index) -> Result<(), Error> {
782+
setup_test_index(&client, &index).await?;
783+
784+
let results = SearchQuery::new(&index)
785+
.with_query("Harry Styles")
786+
.with_matching_strategy(MatchingStrategies::ALL)
787+
.execute::<Document>()
788+
.await
789+
.unwrap();
790+
791+
assert_eq!(results.hits.len(), 0);
792+
Ok(())
793+
}
794+
795+
#[meilisearch_test]
796+
async fn test_matching_strategy_left(client: Client, index: Index) -> Result<(), Error> {
797+
setup_test_index(&client, &index).await?;
798+
799+
let results = SearchQuery::new(&index)
800+
.with_query("Harry Styles")
801+
.with_matching_strategy(MatchingStrategies::LAST)
802+
.execute::<Document>()
803+
.await
804+
.unwrap();
805+
806+
assert_eq!(results.hits.len(), 7);
807+
Ok(())
808+
}
809+
758810
#[meilisearch_test]
759811
async fn test_generate_tenant_token_from_client(
760812
client: Client,

0 commit comments

Comments
 (0)