From 4aa4959c2d609c19f201ae6973c2d528c6bd5424 Mon Sep 17 00:00:00 2001 From: JWSong Date: Sun, 30 Jun 2024 03:30:05 +0900 Subject: [PATCH 1/2] support `searchCutoffMs` setting --- src/settings.rs | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/src/settings.rs b/src/settings.rs index fae8dfe9..0a73e98c 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -103,6 +103,9 @@ pub struct Settings { /// Proximity precision settings. #[serde(skip_serializing_if = "Option::is_none")] pub proximity_precision: Option, + /// SearchCutoffMs settings. + #[serde(skip_serializing_if = "Option::is_none")] + pub search_cutoff_ms: Option, } #[allow(missing_docs)] @@ -288,6 +291,13 @@ impl Settings { ..self } } + + pub fn with_search_cutoff(self, search_cutoff_ms: u64) -> Settings { + Settings { + search_cutoff_ms: Some(search_cutoff_ms), + ..self + } + } } impl Index { @@ -757,6 +767,39 @@ impl Index { .await } + /// Get [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("get_search_cutoff_ms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("get_search_cutoff_ms"); + /// + /// let task = index.get_search_cutoff_ms().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn get_search_cutoff_ms(&self) -> Result, Error> { + self.client + .http_client + .request::<(), (), Option>( + &format!( + "{}/indexes/{}/settings/search-cutoff-ms", + 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. @@ -1350,6 +1393,42 @@ impl Index { .await } + /// Update [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("update_search_cutoff_ms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("update_search_cutoff_ms"); + /// + /// let task = index.set_search_cutoff_ms(Some(150)).await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn set_search_cutoff_ms(&self, ms: Option) -> Result { + self.client + .http_client + .request::<(), Option, TaskInfo>( + &format!( + "{}/indexes/{}/settings/search-cutoff-ms", + self.client.host, self.uid + ), + Method::Put { + body: ms, + query: (), + }, + 202, + ) + .await + } + /// Reset [Settings] of the [Index]. /// /// All settings will be reset to their [default value](https://www.meilisearch.com/docs/reference/api/settings#reset-settings). @@ -1812,6 +1891,39 @@ 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_search_cutoff_ms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// let mut index = client.index("reset_search_cutoff_ms"); + /// + /// let task = index.reset_search_cutoff_ms().await.unwrap(); + /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); + /// # }); + /// ``` + pub async fn reset_search_cutoff_ms(&self) -> Result { + self.client + .http_client + .request::<(), (), TaskInfo>( + &format!( + "{}/indexes/{}/settings/search-cutoff-ms", + self.client.host, self.uid + ), + Method::Delete { query: () }, + 202, + ) + .await + } } #[cfg(test)] @@ -2066,4 +2178,40 @@ mod tests { assert_eq!(expected, default); } + + #[meilisearch_test] + async fn test_get_search_cutoff_ms(index: Index) { + let expected = None; + + let res = index.get_search_cutoff_ms().await.unwrap(); + + assert_eq!(expected, res); + } + + #[meilisearch_test] + async fn test_set_search_cutoff_ms(client: Client, index: Index) { + let expected = Some(150); + + let task_info = index.set_search_cutoff_ms(Some(150)).await.unwrap(); + client.wait_for_task(task_info, None, None).await.unwrap(); + + let res = index.get_search_cutoff_ms().await.unwrap(); + + assert_eq!(expected, res); + } + + #[meilisearch_test] + async fn test_reset_search_cutoff_ms(index: Index) { + let expected = None; + + let task = index.set_search_cutoff_ms(Some(150)).await.unwrap(); + index.wait_for_task(task, None, None).await.unwrap(); + + let reset_task = index.reset_search_cutoff_ms().await.unwrap(); + index.wait_for_task(reset_task, None, None).await.unwrap(); + + let default = index.get_search_cutoff_ms().await.unwrap(); + + assert_eq!(expected, default); + } } From 41a35327b3d89971644b35b12c5d50c197eb0455 Mon Sep 17 00:00:00 2001 From: JWSong Date: Sun, 30 Jun 2024 03:30:31 +0900 Subject: [PATCH 2/2] update .code-sample.meilisearch.yaml --- .code-samples.meilisearch.yaml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 7d96cf6c..a5cb6fd3 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -337,7 +337,8 @@ update_settings_1: |- "release_date" ]) .with_synonyms(synonyms) - .with_typo_tolerance(typo_tolerance); + .with_typo_tolerance(typo_tolerance) + .with_search_cutoff(5); let task: TaskInfo = client .index("movies") @@ -1626,6 +1627,24 @@ reset_proximity_precision_settings_1: |- .reset_proximity_precision() .await .unwrap(); +get_search_cutoff_1: |- + let search_cutoff_ms: String = client + .index("books") + .get_search_cutoff_ms() + .await + .unwrap(); +update_search_cutoff_1: |- + let task: TaskInfo = client + .index("books") + .set_search_cutoff_ms(Some(0)) + .await + .unwrap(); +reset_search_cutoff_1: |- + let task: TaskInfo = client + .index("books") + .reset_search_cutoff_ms() + .await + .unwrap(); create_snapshot_1: |- client .create_snapshot()