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') diff --git a/src/settings.rs b/src/settings.rs index 0a73e98c..97993aff 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 { @@ -800,6 +838,68 @@ impl Index { .await } + /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#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_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(); + /// # 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]. /// /// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged. @@ -1354,6 +1454,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 @@ -1924,6 +2106,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 +2448,26 @@ 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(); + + 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 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 +2482,44 @@ 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 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); + } }