From 0ea31cac589bd9d71ec0938c5a3d767b3e7f706e Mon Sep 17 00:00:00 2001 From: NoodleSamaChan Date: Mon, 1 Jul 2024 17:48:32 +0200 Subject: [PATCH 1/5] added appropriate example to yaml file --- .code-samples.meilisearch.yaml | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index a3eafed3..b37d739a 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -596,6 +596,42 @@ reset_faceting_settings_1: |- .reset_faceting() .await .unwrap(); +get_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .get_dictionary() + .await + .unwrap(); +update_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .set_dictionary(['|', '…']) + .await + .unwrap(); +reset_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .reset_dictionary() + .await + .unwrap(); +get_non_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .get_dictionary() + .await + .unwrap(); +update_non_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .set_dictionary(['@', '#']) + .await + .unwrap(); +reset_non_separator_tokens_1: |- + let task: TaskInfo = client + .index('articles') + .reset_dictionary() + .await + .unwrap(); get_dictionary_1: |- let task: TaskInfo = client .index('books') From f4361c478c3ec5b51bf5a07be8c86bc96cd13d43 Mon Sep 17 00:00:00 2001 From: NoodleSamaChan Date: Mon, 1 Jul 2024 18:26:38 +0200 Subject: [PATCH 2/5] added separator and non separator token functions --- .code-samples.meilisearch.yaml | 9 - src/settings.rs | 314 ++++++++++++++++++++++++++++++++- 2 files changed, 313 insertions(+), 10 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index b37d739a..93c8ab50 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -876,15 +876,6 @@ search_parameter_guide_show_ranking_score_1: |- .execute() .await .unwrap(); -search_parameter_guide_show_ranking_score_details_1: |- - let results: SearchResults = client - .index("movies") - .search() - .with_query("dragon") - .with_show_ranking_score_details(true) - .execute() - .await - .unwrap(); search_parameter_guide_matching_strategy_1: |- let results: SearchResults = client .index("movies") diff --git a/src/settings.rs b/src/settings.rs index 0a73e98c..a8640705 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -106,6 +106,12 @@ pub struct Settings { /// SearchCutoffMs settings. #[serde(skip_serializing_if = "Option::is_none")] pub search_cutoff_ms: Option, + /// Configure strings as custom separator tokens indicating where a word ends and begins. + #[serde(skip_serializing_if = "Option::is_none")] + pub separator_tokens: Option>, + /// Remove tokens from Meilisearch's default [list of word separators](https://www.meilisearch.com/docs/learn/engine/datatypes#string). + #[serde(skip_serializing_if = "Option::is_none")] + pub non_separator_tokens: Option>, } #[allow(missing_docs)] @@ -298,6 +304,38 @@ impl Settings { ..self } } + + #[must_use] + pub fn with_separation_tokens( + self, + separator_tokens: impl IntoIterator>, + ) -> Settings { + Settings { + separator_tokens: Some( + separator_tokens + .into_iter() + .map(|v| v.as_ref().to_string()) + .collect(), + ), + ..self + } + } + + #[must_use] + pub fn with_non_separation_tokens( + self, + non_separator_tokens: impl IntoIterator>, + ) -> Settings { + Settings { + non_separator_tokens: Some( + non_separator_tokens + .into_iter() + .map(|v| v.as_ref().to_string()) + .collect(), + ), + ..self + } + } } impl Index { @@ -799,6 +837,67 @@ impl Index { ) .await } + /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index]. + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*}; + /// # client.create_index("get_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// let index = client.index("get_separator_tokens"); + /// + /// let separator_tokens = index.get_separator_tokens().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn get_separator_tokens(&self) -> Result, Error> { + self.client + .http_client + .request::<(), (), Vec>( + &format!( + "{}/indexes/{}/settings/separator-tokens", + self.client.host, self.uid + ), + Method::Get { query: () }, + 200, + ) + .await + } + + /// Get [non separator token](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) of the [Index]. + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*}; + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("get_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let index = client.index("get_non_separator_tokens"); + /// + /// let non_separator_tokens = index.get_non_separator_tokens().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn get_non_separator_tokens(&self) -> Result, Error> { + self.client + .http_client + .request::<(), (), Vec>( + &format!( + "{}/indexes/{}/settings/non-separator-tokens", + self.client.host, self.uid + ), + Method::Get { query: () }, + 200, + ) + .await + } /// Update [settings](../settings/struct.Settings) of the [Index]. /// @@ -1354,6 +1453,88 @@ impl Index { .await } + /// Update [separator tokens](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) settings of the [Index]. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::{TypoToleranceSettings, MinWordSizeForTypos}}; + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("set_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("set_separator_tokens"); + /// + /// let separator_token: Vec = vec!["@".to_string(), "#".to_string()]; + /// + /// let task = index.set_separator_tokens(&separator_token).await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn set_separator_tokens( + &self, + separator_token: &Vec, + ) -> Result { + self.client + .http_client + .request::<(), &Vec, TaskInfo>( + &format!( + "{}/indexes/{}/settings/separator-tokens", + self.client.host, self.uid + ), + Method::Put { + query: (), + body: separator_token, + }, + 202, + ) + .await + } + + /// Update [non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) settings of the [Index]. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::{TypoToleranceSettings, MinWordSizeForTypos}}; + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("set_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("set_non_separator_tokens"); + /// + /// let non_separator_token: Vec = vec!["@".to_string(), "#".to_string()]; + /// + /// let task = index.set_non_separator_tokens(&non_separator_token).await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn set_non_separator_tokens( + &self, + non_separator_token: &Vec, + ) -> Result { + self.client + .http_client + .request::<(), &Vec, TaskInfo>( + &format!( + "{}/indexes/{}/settings/non-separator-tokens", + self.client.host, self.uid + ), + Method::Put { + query: (), + body: non_separator_token, + }, + 202, + ) + .await + } + /// Update [proximity-precision](https://www.meilisearch.com/docs/learn/configuration/proximity-precision) settings of the [Index]. /// /// # Example @@ -1892,7 +2073,7 @@ impl Index { .await } - /// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index]. + /// Reset [proximity precision](https://www.meilisearch.com/docs/reference/api/settings# /// /// # Example /// @@ -1924,6 +2105,72 @@ impl Index { ) .await } + + /// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index]. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings}; + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("reset_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("reset_separator_tokens"); + /// + /// let task = index.reset_separator_tokens().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn reset_separator_tokens(&self) -> Result { + self.client + .http_client + .request::<(), (), TaskInfo>( + &format!( + "{}/indexes/{}/settings/separator-tokens", + self.client.host, self.uid + ), + Method::Delete { query: () }, + 202, + ) + .await + } + + /// Reset [non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) settings of the [Index]. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings}; + /// # + /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// # + /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { + /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("reset_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("reset_non_separator_tokens"); + /// + /// let task = index.reset_non_separator_tokens().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn reset_non_separator_tokens(&self) -> Result { + self.client + .http_client + .request::<(), (), TaskInfo>( + &format!( + "{}/indexes/{}/settings/non-separator-tokens", + self.client.host, self.uid + ), + Method::Delete { query: () }, + 202, + ) + .await + } } #[cfg(test)] @@ -2200,6 +2447,28 @@ mod tests { assert_eq!(expected, res); } + async fn test_get_separator_tokens(index: Index) { + let separator: Vec<&str> = vec![]; + let res = index.get_separator_tokens().await.unwrap(); + + assert_eq!(separator, res); + } + + #[meilisearch_test] + async fn test_set_separator_tokens(client: Client, index: Index) { + let expected: Vec = vec!["@".to_string(), "#".to_string()]; + + let task_info = index + .set_separator_tokens(&expected) + .await + .unwrap(); + client.wait_for_task(task_info, None, None).await.unwrap(); + + let mut res = index.get_separator_tokens().await.unwrap(); + + assert_eq!(expected, res); + } + #[meilisearch_test] async fn test_reset_search_cutoff_ms(index: Index) { let expected = None; @@ -2214,4 +2483,47 @@ mod tests { assert_eq!(expected, default); } + + #[meilisearch_test] + async fn test_reset_separator_tokens(client: Client, index: Index) { + let separator: Vec<&str> = vec![]; + let task_info = index.reset_separator_tokens().await.unwrap(); + client.wait_for_task(task_info, None, None).await.unwrap(); + + let res = index.get_dictionary().await.unwrap(); + assert_eq!(separator, res); + } + + #[meilisearch_test] + async fn test_get_non_separator_tokens(index: Index) { + let separator: Vec<&str> = vec![]; + let res = index.get_non_separator_tokens().await.unwrap(); + + assert_eq!(separator, res); + } + + #[meilisearch_test] + async fn test_set_non_separator_tokens(client: Client, index: Index) { + let expected: Vec = vec![ "@".to_string(), "#".to_string()]; + + let task_info = index + .set_non_separator_tokens(&expected) + .await + .unwrap(); + client.wait_for_task(task_info, None, None).await.unwrap(); + + let mut res = index.get_non_separator_tokens().await.unwrap(); + + assert_eq!(expected, res); + } + + #[meilisearch_test] + async fn test_reset_non_separator_tokens(client: Client, index: Index) { + let separator: Vec<&str> = vec![]; + let task_info = index.reset_non_separator_tokens().await.unwrap(); + client.wait_for_task(task_info, None, None).await.unwrap(); + + let res = index.get_dictionary().await.unwrap(); + assert_eq!(separator, res); + } } From c57d0b252de4c435294955278d69e41eff996ffa Mon Sep 17 00:00:00 2001 From: NoodleSamaChan <150461421+NoodleSamaChan@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:29:58 +0200 Subject: [PATCH 3/5] Update src/settings.rs Co-authored-by: Tamo --- src/settings.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index a8640705..ebc63ecb 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -837,7 +837,8 @@ impl Index { ) .await } - /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index]. + + /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index]. /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; From 979d4605fdea9f045fa78717863c7c9a980c0feb Mon Sep 17 00:00:00 2001 From: NoodleSamaChan <150461421+NoodleSamaChan@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:30:09 +0200 Subject: [PATCH 4/5] Update src/settings.rs Co-authored-by: Tamo --- src/settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index ebc63ecb..d111d8b3 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2074,7 +2074,7 @@ impl Index { .await } - /// Reset [proximity precision](https://www.meilisearch.com/docs/reference/api/settings# + /// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index]. /// /// # Example /// From 968dfab9b279e48739a14f8cd0922351fb1e7b72 Mon Sep 17 00:00:00 2001 From: NoodleSamaChan Date: Tue, 2 Jul 2024 11:41:19 +0200 Subject: [PATCH 5/5] changed some rebase issues --- .code-samples.meilisearch.yaml | 9 +++++++++ src/settings.rs | 25 ++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 93c8ab50..b37d739a 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -876,6 +876,15 @@ search_parameter_guide_show_ranking_score_1: |- .execute() .await .unwrap(); +search_parameter_guide_show_ranking_score_details_1: |- + let results: SearchResults = client + .index("movies") + .search() + .with_query("dragon") + .with_show_ranking_score_details(true) + .execute() + .await + .unwrap(); search_parameter_guide_matching_strategy_1: |- let results: SearchResults = client .index("movies") diff --git a/src/settings.rs b/src/settings.rs index d111d8b3..97993aff 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -838,17 +838,17 @@ impl Index { .await } - /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index]. + /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index]. /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; - /// # client.create_index("get_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async { /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap(); + /// # client.create_index("get_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_separator_tokens"); /// /// let separator_tokens = index.get_separator_tokens().await.unwrap(); @@ -2108,7 +2108,7 @@ impl Index { } /// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index]. - /// + /// /// # Example /// /// ``` @@ -2448,6 +2448,7 @@ mod tests { assert_eq!(expected, res); } + #[meilisearch_test] async fn test_get_separator_tokens(index: Index) { let separator: Vec<&str> = vec![]; let res = index.get_separator_tokens().await.unwrap(); @@ -2457,15 +2458,12 @@ mod tests { #[meilisearch_test] async fn test_set_separator_tokens(client: Client, index: Index) { - let expected: Vec = vec!["@".to_string(), "#".to_string()]; + let expected: Vec = vec!["#".to_string(), "@".to_string()]; - let task_info = index - .set_separator_tokens(&expected) - .await - .unwrap(); + let task_info = index.set_separator_tokens(&expected).await.unwrap(); client.wait_for_task(task_info, None, None).await.unwrap(); - let mut res = index.get_separator_tokens().await.unwrap(); + let res = index.get_separator_tokens().await.unwrap(); assert_eq!(expected, res); } @@ -2505,15 +2503,12 @@ mod tests { #[meilisearch_test] async fn test_set_non_separator_tokens(client: Client, index: Index) { - let expected: Vec = vec![ "@".to_string(), "#".to_string()]; + let expected: Vec = vec!["#".to_string(), "@".to_string()]; - let task_info = index - .set_non_separator_tokens(&expected) - .await - .unwrap(); + let task_info = index.set_non_separator_tokens(&expected).await.unwrap(); client.wait_for_task(task_info, None, None).await.unwrap(); - let mut res = index.get_non_separator_tokens().await.unwrap(); + let res = index.get_non_separator_tokens().await.unwrap(); assert_eq!(expected, res); }