From ee59aaf00a1ec60044632f85efd4d90af9e7e849 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 09:08:34 -0400 Subject: [PATCH 1/7] Project-wide doc comment adjustments Applying `cargo clippy` suggestions, spell checking, and cleaning up where project norms are not upheld. *Please see PR for methodology and full list of explanations* --- examples/cli-app/src/main.rs | 8 +- examples/web_app/README.md | 2 +- src/dumps.rs | 24 ++-- src/indexes.rs | 219 +++++++++++++++++------------------ src/key.rs | 94 ++++++++------- src/lib.rs | 6 +- 6 files changed, 172 insertions(+), 181 deletions(-) diff --git a/examples/cli-app/src/main.rs b/examples/cli-app/src/main.rs index f2c3551e..7d929db0 100644 --- a/examples/cli-app/src/main.rs +++ b/examples/cli-app/src/main.rs @@ -67,13 +67,13 @@ async fn build_index() { // serialize the string to clothes objects let clothes: Vec = serde_json::from_str(content).unwrap(); - //create displayed attributes + // create displayed attributes let displayed_attributes = ["article", "cost", "size", "pattern"]; // Create ranking rules let ranking_rules = ["words", "typo", "attribute", "exactness", "cost:asc"]; - //create searchable attributes + // create searchable attributes let searchable_attributes = ["seaon", "article", "size", "pattern"]; // create the synonyms hashmap @@ -82,14 +82,14 @@ async fn build_index() { synonyms.insert("sweat pants", vec!["joggers", "gym pants"]); synonyms.insert("t-shirt", vec!["tees", "tshirt"]); - //create the settings struct + // create the settings struct let settings = Settings::new() .with_ranking_rules(ranking_rules) .with_searchable_attributes(searchable_attributes) .with_displayed_attributes(displayed_attributes) .with_synonyms(synonyms); - //add the settings to the index + // add the settings to the index let result = CLIENT .index("clothes") .set_settings(&settings) diff --git a/examples/web_app/README.md b/examples/web_app/README.md index ae28fb90..da1e89ca 100644 --- a/examples/web_app/README.md +++ b/examples/web_app/README.md @@ -1,7 +1,7 @@ # Build your front-end page in Rust with WebAssembly > **Note** -> It is not possible to run Meilisearch in the browser without a server. This demo uses the Rust SDK in a browser using WASM, and communicate with a Meilisearch instance that is running on a remote server. +> It is not possible to run Meilisearch in the browser without a server. This demo uses the Rust SDK in a browser using WASM, and communicates with a Meilisearch instance that is running on a remote server. This example is a clone of [crates.meilisearch.com](https://crates.meilisearch.com), but the front-end is written in Rust! The Rust source files are compiled into WebAssembly and so can be readable by the browsers. diff --git a/src/dumps.rs b/src/dumps.rs index 662dfc14..61bc4dff 100644 --- a/src/dumps.rs +++ b/src/dumps.rs @@ -28,18 +28,18 @@ //! // Create a dump //! let task_info = client.create_dump().await.unwrap(); //! assert!(matches!( -//! task_info, -//! TaskInfo { -//! update_type: TaskType::DumpCreation { .. }, -//! .. -//! } -//!)); +//! task_info, +//! TaskInfo { +//! update_type: TaskType::DumpCreation { .. }, +//! .. +//! } +//! )); //! # }); //! ``` use crate::{client::Client, errors::Error, request::*, task_info::TaskInfo}; -/// Dump related methods.\ +/// Dump related methods. /// See the [dumps](crate::dumps) module. impl Client { /// Triggers a dump creation process. @@ -61,11 +61,11 @@ impl Client { /// # /// let task_info = client.create_dump().await.unwrap(); /// assert!(matches!( - /// task_info, - /// TaskInfo { - /// update_type: TaskType::DumpCreation { .. }, - /// .. - /// } + /// task_info, + /// TaskInfo { + /// update_type: TaskType::DumpCreation { .. }, + /// .. + /// } /// )); /// # }); /// ``` diff --git a/src/indexes.rs b/src/indexes.rs index 23201236..0dc973d6 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -808,18 +808,17 @@ impl Index { /// # /// # futures::executor::block_on(async move { /// # - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("delete_all_documents"); - /// + /// # /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// // add some documents - /// + /// # /// movie_index.delete_all_documents() - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// let movies = movie_index.get_documents::().await.unwrap(); /// assert_eq!(movies.results.len(), 0); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -855,18 +854,16 @@ impl Index { /// # /// # futures::executor::block_on(async move { /// # - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut movies = client.index("delete_document"); - /// /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// // add a document with id = Interstellar - /// /// movies.delete_document("Interstellar") - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -903,19 +900,19 @@ impl Index { /// # /// # futures::executor::block_on(async move { /// # - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("delete_documents"); - /// - /// // add some documents + /// # + /// # // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// + /// # /// // delete some documents /// movies.delete_documents(&["Interstellar", "Unknown"]) - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -959,10 +956,9 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # // create the client + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("fetch_info", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// /// // get the information of the index named "fetch_info" /// let mut idx = client.index("fetch_info"); /// idx.fetch_info().await.unwrap(); @@ -970,6 +966,9 @@ impl Index { /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` + /// + /// # Note + /// /// If you use it directly from the [Client], you can use the method [Client::get_raw_index], which is the equivalent method from the client. pub async fn fetch_info(&mut self) -> Result<(), Error> { let v = self.client.get_raw_index(&self.uid).await?; @@ -988,10 +987,9 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// # let mut index = client.create_index("get_primary_key", Some("id")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// + /// # // create the client + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// let mut index = client.create_index("get_primary_key", Some("id")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let primary_key = index.get_primary_key().await.unwrap(); /// /// assert_eq!(primary_key, Some("id")); @@ -1037,13 +1035,13 @@ impl Index { /// let status = movies.get_task(&task).await.unwrap(); /// /// let from_index = match status { - /// Task::Enqueued { content } => content.uid, - /// Task::Processing { content } => content.uid, - /// Task::Failed { content } => content.task.uid, - /// Task::Succeeded { content } => content.uid, + /// Task::Enqueued { content } => content.uid, + /// Task::Processing { content } => content.uid, + /// Task::Failed { content } => content.task.uid, + /// Task::Succeeded { content } => content.uid, /// }; /// - /// assert_eq!(task.get_task_uid(), from_index); + /// # assert_eq!(task.get_task_uid(), from_index); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1071,10 +1069,9 @@ impl Index { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_tasks", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// /// let tasks = index.get_tasks().await.unwrap(); /// - /// assert!(tasks.results.len() > 0); + /// # assert!(tasks.results.len() > 0); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1099,12 +1096,11 @@ impl Index { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_tasks_with", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// /// let mut query = TasksSearchQuery::new(&client); /// query.with_index_uids(["none_existant"]); /// let tasks = index.get_tasks_with(&query).await.unwrap(); /// - /// assert!(tasks.results.len() > 0); + /// # assert!(tasks.results.len() > 0); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1131,9 +1127,8 @@ impl Index { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_stats", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// /// let stats = index.get_stats().await.unwrap(); - /// assert_eq!(stats.is_indexing, false); + /// # assert_eq!(stats.is_indexing, false); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1174,7 +1169,7 @@ impl Index { /// # /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("movies_index_wait_for_task"); /// /// let task = movies.add_documents(&[ @@ -1184,7 +1179,7 @@ impl Index { /// /// let status = movies.wait_for_task(task, None, None).await.unwrap(); /// - /// assert!(matches!(status, Task::Succeeded { .. })); + /// # assert!(matches!(status, Task::Succeeded { .. })); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1197,19 +1192,19 @@ impl Index { self.client.wait_for_task(task_id, interval, timeout).await } - /// Add documents to the index in batches + /// Add documents to the index in batches. /// /// `documents` = A slice of documents + /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch + /// /// `batch_size` is 1000 by default /// /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// use meilisearch_sdk::client::*; - /// - /// # + /// # use serde::{Serialize, Deserialize}; + /// # use meilisearch_sdk::client::*; /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # @@ -1220,7 +1215,7 @@ impl Index { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_documents_in_batches"); /// /// let tasks = movie_index.add_documents_in_batches(&[ @@ -1244,9 +1239,9 @@ impl Index { /// client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap(); /// /// let movies = movie_index.get_documents::().await.unwrap(); - /// assert!(movies.results.len() >= 3); + /// # assert!(movies.results.len() >= 3); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, - /// None).await.unwrap(); + /// # None).await.unwrap(); /// # }); /// ``` pub async fn add_documents_in_batches( @@ -1262,19 +1257,19 @@ impl Index { Ok(task) } - /// Update documents to the index in batches + /// Update documents to the index in batches. /// /// `documents` = A slice of documents + /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch + /// /// `batch_size` is 1000 by default /// /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// use meilisearch_sdk::client::*; - /// - /// # + /// # use serde::{Serialize, Deserialize}; + /// # use meilisearch_sdk::client::*; /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # @@ -1285,7 +1280,7 @@ impl Index { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("update_documents_in_batches"); /// /// let tasks = movie_index.add_documents_in_batches(&[ @@ -1332,10 +1327,9 @@ impl Index { /// /// let movies_updated = movie_index.get_documents::().await.unwrap(); /// - /// assert!(movies_updated.results.len() >= 3); - /// + /// # assert!(movies_updated.results.len() >= 3); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, - /// None).await.unwrap(); + /// # None).await.unwrap(); /// # }); /// ``` pub async fn update_documents_in_batches( @@ -1358,16 +1352,16 @@ impl AsRef for Index { } } -/// An [IndexUpdater] used to update the specifics of an index +/// An [IndexUpdater] used to update the specifics of an index. /// /// # Example /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*, task_info::*, tasks::{Task, SucceededTask}}; -/// # +/// /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); -/// # +/// /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client @@ -1380,18 +1374,17 @@ impl AsRef for Index { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); -/// /// let task = IndexUpdater::new("index_updater", &client) -/// .with_primary_key("special_id") -/// .execute() -/// .await -/// .unwrap() -/// .wait_for_completion(&client, None, None) -/// .await -/// .unwrap(); +/// .with_primary_key("special_id") +/// .execute() +/// .await +/// .unwrap() +/// .wait_for_completion(&client, None, None) +/// .await +/// .unwrap(); /// /// let index = client.get_index("index_updater").await.unwrap(); -/// assert_eq!(index.primary_key, Some("special_id".to_string())); +/// # assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1413,7 +1406,7 @@ impl<'a> IndexUpdater<'a> { uid: uid.as_ref().to_string(), } } - /// Define the new primary_key to set on the [Index] + /// Define the new primary_key to set on the [Index]. /// /// # Example /// @@ -1435,18 +1428,17 @@ impl<'a> IndexUpdater<'a> { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// /// let task = IndexUpdater::new("index_updater_with_primary_key", &client) - /// .with_primary_key("special_id") - /// .execute() - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .with_primary_key("special_id") + /// .execute() + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// let index = client.get_index("index_updater_with_primary_key").await.unwrap(); - /// assert_eq!(index.primary_key, Some("special_id".to_string())); + /// # assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1455,7 +1447,7 @@ impl<'a> IndexUpdater<'a> { self } - /// Execute the update of an [Index] using the [IndexUpdater] + /// Execute the update of an [Index] using the [IndexUpdater]. /// /// # Example /// @@ -1477,18 +1469,17 @@ impl<'a> IndexUpdater<'a> { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// /// let task = IndexUpdater::new("index_updater_execute", &client) - /// .with_primary_key("special_id") - /// .execute() - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .with_primary_key("special_id") + /// .execute() + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// let index = client.get_index("index_updater_execute").await.unwrap(); - /// assert_eq!(index.primary_key, Some("special_id".to_string())); + /// # assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1526,7 +1517,7 @@ pub struct IndexStats { pub field_distribution: HashMap, } -// An [IndexesQuery] containing filter and pagination parameters when searching for [Index]es +/// An [IndexesQuery] containing filter and pagination parameters when searching for [Indexes](Index). /// /// # Example /// @@ -1548,9 +1539,9 @@ pub struct IndexStats { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); -/// let mut indexes = IndexesQuery::new(&client) -/// .with_limit(1) -/// .execute().await.unwrap(); +/// let mut indexes = IndexesQuery::new(&client) +/// .with_limit(1) +/// .execute().await.unwrap(); /// /// # assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -1561,7 +1552,8 @@ pub struct IndexStats { pub struct IndexesQuery<'a> { #[serde(skip_serializing)] pub client: &'a Client, - /// The number of [Index]es to skip. + /// The number of [Indexes](Index) to skip. + /// /// If the value of the parameter `offset` is `n`, the `n` first indexes will not be returned. /// This is helpful for pagination. /// @@ -1569,11 +1561,13 @@ pub struct IndexesQuery<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub offset: Option, - /// The maximum number of [Index]es returned. + /// The maximum number of [Indexes](Index) returned. + /// /// If the value of the parameter `limit` is `n`, there will never be more than `n` indexes in the response. /// This is helpful for pagination. /// /// Example: If you don't want to get more than two indexes, set limit to `2`. + /// /// Default: `20` #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, @@ -1610,10 +1604,9 @@ impl<'a> IndexesQuery<'a> { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// - /// let mut indexes = IndexesQuery::new(&client) - /// .with_offset(1) - /// .execute().await.unwrap(); + /// let mut indexes = IndexesQuery::new(&client) + /// .with_offset(1) + /// .execute().await.unwrap(); /// /// # assert_eq!(indexes.offset, 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -1624,7 +1617,7 @@ impl<'a> IndexesQuery<'a> { self } - /// Specify the maximum number of [Index]es to return. + /// Specify the maximum number of [Indexes](Index) to return. /// /// # Example /// @@ -1646,9 +1639,9 @@ impl<'a> IndexesQuery<'a> { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// let mut indexes = IndexesQuery::new(&client) - /// .with_limit(1) - /// .execute().await.unwrap(); + /// let mut indexes = IndexesQuery::new(&client) + /// .with_limit(1) + /// .execute().await.unwrap(); /// /// # assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -1658,7 +1651,7 @@ impl<'a> IndexesQuery<'a> { self.limit = Some(limit); self } - /// Get [Index]es. + /// Get [Indexes](Index). /// /// # Example /// @@ -1680,9 +1673,9 @@ impl<'a> IndexesQuery<'a> { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// let mut indexes = IndexesQuery::new(&client) - /// .with_limit(1) - /// .execute().await.unwrap(); + /// let mut indexes = IndexesQuery::new(&client) + /// .with_limit(1) + /// .execute().await.unwrap(); /// /// # assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); diff --git a/src/key.rs b/src/key.rs index 66ec8acd..8c6f4994 100644 --- a/src/key.rs +++ b/src/key.rs @@ -3,9 +3,9 @@ use time::OffsetDateTime; use crate::{client::Client, errors::Error}; -/// Represent a [meilisearch key](https://docs.meilisearch.com/reference/api/keys.html#returned-fields) -/// You can get a [Key] from the [Client::get_key] method. -/// Or you can create a [Key] with the [KeyBuilder::new] or [Client::create_key] methods. +/// Represents a [meilisearch key](https://docs.meilisearch.com/reference/api/keys.html#returned-fields). +/// +/// You can get a [Key] from the [Client::get_key] method, or you can create a [Key] with the [KeyBuilder::new] or [Client::create_key] methods. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] pub struct Key { @@ -95,7 +95,7 @@ impl Key { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut key = KeyBuilder::new() /// .execute(&client).await.unwrap(); /// let description = "My not so little lovely test key".to_string(); @@ -131,9 +131,9 @@ impl Key { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut key = KeyBuilder::new() - /// .execute(&client).await.unwrap(); + /// .execute(&client).await.unwrap(); /// /// client.delete_key(key).await.unwrap(); /// # }); @@ -185,7 +185,7 @@ impl KeyUpdater { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut new_key = KeyBuilder::new() + /// let mut new_key = KeyBuilder::new() /// .execute(&client) /// .await /// .unwrap(); @@ -218,13 +218,12 @@ impl KeyUpdater { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut new_key = KeyBuilder::new() + /// let mut new_key = KeyBuilder::new() /// .execute(&client) /// .await /// .unwrap(); /// /// let name = "lovely key".to_string(); - /// /// let mut key_update = KeyUpdater::new(new_key) /// .with_name(&name) /// .execute(&client) @@ -251,15 +250,15 @@ impl KeyUpdater { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let description = "My little lovely test key".to_string(); /// let key = KeyBuilder::new() - /// .execute(&client).await.unwrap(); + /// .execute(&client).await.unwrap(); /// /// let mut key_update = KeyUpdater::new(&key.key); /// key_update.with_description(&description).execute(&client).await; /// - /// assert_eq!(key_update.description, Some(description)); + /// # assert_eq!(key_update.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -284,6 +283,7 @@ impl AsRef for KeyUpdater { #[serde(rename_all = "camelCase")] pub struct KeysQuery { /// The number of documents to skip. + /// /// If the value of the parameter `offset` is `n`, the `n` first documents (ordered by relevance) will not be returned. /// This is helpful for pagination. /// @@ -291,6 +291,7 @@ pub struct KeysQuery { #[serde(skip_serializing_if = "Option::is_none")] pub offset: Option, /// The maximum number of documents returned. + /// /// If the value of the parameter `limit` is `n`, there will never be more than `n` documents in the response. /// This is helpful for pagination. /// @@ -325,9 +326,9 @@ impl KeysQuery { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut keys = KeysQuery::new() - /// .with_offset(1) - /// .execute(&client).await.unwrap(); + /// let mut keys = KeysQuery::new() + /// .with_offset(1) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(keys.offset, 1); /// # }); @@ -349,9 +350,9 @@ impl KeysQuery { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut keys = KeysQuery::new() - /// .with_limit(1) - /// .execute(&client).await.unwrap(); + /// let mut keys = KeysQuery::new() + /// .with_limit(1) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(keys.results.len(), 1); /// # }); @@ -373,9 +374,9 @@ impl KeysQuery { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut keys = KeysQuery::new() - /// .with_limit(1) - /// .execute(&client).await.unwrap(); + /// let mut keys = KeysQuery::new() + /// .with_limit(1) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(keys.results.len(), 1); /// # }); @@ -386,6 +387,7 @@ impl KeysQuery { } /// The [KeyBuilder] is an analog to the [Key] type but without all the fields managed by Meilisearch. +/// /// It's used to create [Key]. /// /// # Example @@ -397,11 +399,11 @@ impl KeysQuery { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { -/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); +/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let description = "My little lovely test key".to_string(); /// let key = KeyBuilder::new() -/// .with_description(&description) -/// .execute(&client).await.unwrap(); +/// .with_description(&description) +/// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); @@ -469,7 +471,7 @@ impl KeyBuilder { /// /// ``` /// # use meilisearch_sdk::{key::KeyBuilder}; - /// use time::{OffsetDateTime, Duration}; + /// # use time::{OffsetDateTime, Duration}; /// let mut builder = KeyBuilder::new(); /// // create a key that expires in two weeks from now /// builder.with_expires_at(OffsetDateTime::now_utc() + Duration::WEEK * 2); @@ -492,10 +494,10 @@ impl KeyBuilder { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut key = KeyBuilder::new() - /// .with_indexes(vec!["test", "movies"]) - /// .execute(&client) - /// .await - /// .unwrap(); + /// .with_indexes(vec!["test", "movies"]) + /// .execute(&client) + /// .await + /// .unwrap(); /// /// assert_eq!(vec!["test", "movies"], key.indexes); /// # client.delete_key(key).await.unwrap(); @@ -538,11 +540,10 @@ impl KeyBuilder { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let description = "My not so little lovely test key".to_string(); - /// - /// let mut key = KeyBuilder::new() - /// .with_description(&description) - /// .execute(&client).await.unwrap(); + /// let description = "My not so little lovely test key".to_string(); + /// let mut key = KeyBuilder::new() + /// .with_description(&description) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); @@ -565,11 +566,10 @@ impl KeyBuilder { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let name = "lovely key".to_string(); - /// - /// let mut key = KeyBuilder::new() - /// .with_name(&name) - /// .execute(&client).await.unwrap(); + /// let name = "lovely key".to_string(); + /// let mut key = KeyBuilder::new() + /// .with_name(&name) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); @@ -592,12 +592,10 @@ impl KeyBuilder { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let uid = "93bcd7fb-2196-4fd9-acb7-3fca8a96e78f".to_string(); - /// - /// let mut key = KeyBuilder::new() - /// .with_uid(&uid) - /// .execute(&client).await.unwrap(); - /// + /// let uid = "93bcd7fb-2196-4fd9-acb7-3fca8a96e78f".to_string(); + /// let mut key = KeyBuilder::new() + /// .with_uid(&uid) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.uid, uid); /// # client.delete_key(key).await.unwrap(); @@ -619,11 +617,11 @@ impl KeyBuilder { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let description = "My little lovely test key".to_string(); /// let key = KeyBuilder::new() - /// .with_description(&description) - /// .execute(&client).await.unwrap(); + /// .with_description(&description) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 3973f33a..9b401adb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ //! //! ### Add Documents //! -//! ```rust +//! ``` //! use meilisearch_sdk::client::*; //! use serde::{Serialize, Deserialize}; //! use futures::executor::block_on; @@ -42,7 +42,7 @@ //! //! ### Basic Search //! -//! ```rust +//! ``` //! # use meilisearch_sdk::client::*; //! # use serde::{Serialize, Deserialize}; //! # use futures::executor::block_on; @@ -85,7 +85,7 @@ //! //! ### Custom Search //! -//! ```rust +//! ``` //! # use meilisearch_sdk::{client::*, search::*}; //! # use serde::{Serialize, Deserialize}; //! # use futures::executor::block_on; From d8984ace38e11fbfe953d11a012b2051f513f367 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 12:38:29 -0400 Subject: [PATCH 2/7] util through settings --- src/client.rs | 2 + src/key.rs | 8 +-- src/settings.rs | 140 +++++++++++++++++++++++++++++++---------------- src/task_info.rs | 17 +++--- src/tasks.rs | 50 +++++++++-------- 5 files changed, 135 insertions(+), 82 deletions(-) diff --git a/src/client.rs b/src/client.rs index 10c840a7..17b3c88d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -344,8 +344,10 @@ impl Client { } /// Create an [Index]. + /// /// The second parameter will be used as the primary key of the new index. /// If it is not specified, Meilisearch will **try** to infer the primary key. + /// /// # Example /// /// ``` diff --git a/src/key.rs b/src/key.rs index 8c6f4994..81b9c1af 100644 --- a/src/key.rs +++ b/src/key.rs @@ -42,10 +42,10 @@ impl Key { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let description = "My not so little lovely test key".to_string(); /// let mut key = KeyBuilder::new() - /// .with_action(Action::DocumentsAdd) - /// .with_index("*") - /// .with_description(&description) - /// .execute(&client).await.unwrap(); + /// .with_action(Action::DocumentsAdd) + /// .with_index("*") + /// .with_description(&description) + /// .execute(&client).await.unwrap(); /// /// # assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); diff --git a/src/settings.rs b/src/settings.rs index 20f70a35..92c3c204 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -20,6 +20,7 @@ pub struct FacetingSettings { } /// Struct reprensenting a set of settings. +/// /// You can build this struct using the builder syntax. /// /// # Example @@ -46,41 +47,41 @@ pub struct FacetingSettings { #[derive(Serialize, Deserialize, Default, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Settings { - /// List of associated words treated similarly + /// List of associated words treated similarly. #[serde(skip_serializing_if = "Option::is_none")] pub synonyms: Option>>, - /// List of words ignored by Meilisearch when present in search queries + /// List of words ignored by Meilisearch when present in search queries. #[serde(skip_serializing_if = "Option::is_none")] pub stop_words: Option>, - /// List of [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#order-of-the-rules) sorted by order of importance + /// List of [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#order-of-the-rules) sorted by order of importance. #[serde(skip_serializing_if = "Option::is_none")] pub ranking_rules: Option>, - /// Attributes to use for [filtering and faceted search](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html) + /// Attributes to use for [filtering and faceted search](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html). #[serde(skip_serializing_if = "Option::is_none")] pub filterable_attributes: Option>, - /// Attributes to sort + /// Attributes to sort. #[serde(skip_serializing_if = "Option::is_none")] pub sortable_attributes: Option>, - /// Search returns documents with distinct (different) values of the given field + /// Search returns documents with distinct (different) values of the given field. #[serde(skip_serializing_if = "Option::is_none")] pub distinct_attribute: Option, - /// Fields in which to search for matching query words sorted by order of importance + /// Fields in which to search for matching query words sorted by order of importance. #[serde(skip_serializing_if = "Option::is_none")] pub searchable_attributes: Option>, - /// Fields displayed in the returned documents + /// Fields displayed in the returned documents. #[serde(skip_serializing_if = "Option::is_none")] pub displayed_attributes: Option>, - /// Pagination settings + /// Pagination settings. #[serde(skip_serializing_if = "Option::is_none")] pub pagination: Option, - /// Faceting settings + /// Faceting settings. #[serde(skip_serializing_if = "Option::is_none")] pub faceting: Option, } #[allow(missing_docs)] impl Settings { - /// Create undefined settings + /// Create undefined settings. pub fn new() -> Settings { Settings { synonyms: None, @@ -232,6 +233,8 @@ impl Settings { impl Index { /// Get [Settings] of the [Index]. /// + /// # Example + /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; /// # @@ -239,9 +242,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_settings", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_settings"); + /// /// let settings = index.get_settings().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -257,6 +261,9 @@ impl Index { } /// Get [synonyms](https://docs.meilisearch.com/reference/features/synonyms.html) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -265,9 +272,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_synonyms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_synonyms"); + /// /// let synonyms = index.get_synonyms().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -286,6 +294,9 @@ impl Index { } /// Get [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -294,9 +305,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_pagination"); + /// /// let pagination = index.get_pagination().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -316,6 +328,8 @@ impl Index { /// Get [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index]. /// + /// # Example + /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; /// # @@ -323,9 +337,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_stop_words", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_stop_words"); + /// /// let stop_words = index.get_stop_words().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -344,6 +359,9 @@ impl Index { } /// Get [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#ranking-rules) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -352,9 +370,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_ranking_rules", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_ranking_rules"); + /// /// let ranking_rules = index.get_ranking_rules().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -373,6 +392,9 @@ impl Index { } /// Get [filterable attributes](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -381,9 +403,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_filterable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_filterable_attributes"); + /// /// let filterable_attributes = index.get_filterable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -402,6 +425,9 @@ impl Index { } /// Get [sortable attributes](https://docs.meilisearch.com/reference/features/sorting.html) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -410,9 +436,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_sortable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_sortable_attributes"); + /// /// let sortable_attributes = index.get_sortable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -431,6 +458,9 @@ impl Index { } /// Get the [distinct attribute](https://docs.meilisearch.com/reference/features/settings.html#distinct-attribute) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -439,9 +469,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_distinct_attribute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_distinct_attribute"); + /// /// let distinct_attribute = index.get_distinct_attribute().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -460,6 +491,9 @@ impl Index { } /// Get [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -468,9 +502,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_searchable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_searchable_attributes"); + /// /// let searchable_attributes = index.get_searchable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -489,6 +524,9 @@ impl Index { } /// Get [displayed attributes](https://docs.meilisearch.com/reference/features/settings.html#displayed-attributes) of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -497,9 +535,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_displayed_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_displayed_attributes"); + /// /// let displayed_attributes = index.get_displayed_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -518,6 +557,9 @@ impl Index { } /// Get [faceting](https://docs.meilisearch.com/reference/api/settings.html#faceting) settings of the [Index]. + /// + /// # Example + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -526,9 +568,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_faceting"); + /// /// let faceting = index.get_faceting().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -547,6 +590,7 @@ impl Index { } /// Update [settings](../settings/struct.Settings.html) of the [Index]. + /// /// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged. /// /// # Example @@ -558,7 +602,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_settings", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_settings"); /// @@ -596,7 +640,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_synonyms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_synonyms"); /// @@ -639,9 +683,10 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_pagination"); + /// /// let pagination = PaginationSetting {max_total_hits:100}; /// let task = index.set_pagination(pagination).await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -674,7 +719,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_stop_words", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_stop_words"); /// @@ -716,7 +761,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_ranking_rules", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_ranking_rules"); /// @@ -767,7 +812,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_filterable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_filterable_attributes"); /// @@ -809,7 +854,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_sortable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_sortable_attributes"); /// @@ -851,7 +896,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_distinct_attribute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_distinct_attribute"); /// @@ -889,7 +934,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_searchable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_searchable_attributes"); /// @@ -930,7 +975,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_displayed_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_displayed_attributes"); /// @@ -971,7 +1016,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_faceting"); /// @@ -1000,6 +1045,7 @@ impl Index { } /// Reset [Settings] of the [Index]. + /// /// All settings will be reset to their [default value](https://docs.meilisearch.com/reference/api/settings.html#reset-settings). /// /// # Example @@ -1011,7 +1057,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_settings", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_settings"); /// @@ -1040,7 +1086,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_synonyms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_synonyms"); /// @@ -1072,7 +1118,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_pagination"); /// @@ -1103,7 +1149,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_stop_words", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_stop_words"); /// @@ -1125,7 +1171,8 @@ impl Index { } /// Reset [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#ranking-rules) of the [Index] to default value. - /// Default value: `["words", "typo", "proximity", "attribute", "sort", "exactness"]`. + /// + /// **Default value: `["words", "typo", "proximity", "attribute", "sort", "exactness"]`.** /// /// # Example /// @@ -1136,7 +1183,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_ranking_rules", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_ranking_rules"); /// @@ -1168,7 +1215,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_filterable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_filterable_attributes"); /// @@ -1200,7 +1247,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_sortable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_sortable_attributes"); /// @@ -1232,7 +1279,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_distinct_attribute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_distinct_attribute"); /// @@ -1253,7 +1300,8 @@ impl Index { .await } - /// Reset [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of the [Index] (enable all attributes). + /// Reset [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of + /// the [Index] (enable all attributes). /// /// # Example /// @@ -1264,7 +1312,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_searchable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_searchable_attributes"); /// @@ -1296,7 +1344,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_displayed_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_displayed_attributes"); /// @@ -1328,7 +1376,7 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("reset_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("reset_faceting"); /// diff --git a/src/task_info.rs b/src/task_info.rs index e7cdafa7..2f796fcf 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -29,8 +29,9 @@ impl TaskInfo { /// Wait until Meilisearch processes a task provided by [TaskInfo], and get its status. /// - /// `interval` = The frequency at which the server should be polled. Default = 50ms - /// `timeout` = The maximum time to wait for processing to complete. Default = 5000ms + /// `interval` = The frequency at which the server should be polled. **Default = 50ms** + /// + /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. /// @@ -51,18 +52,18 @@ impl TaskInfo { /// # /// # /// # futures::executor::block_on(async move { - /// let client = Client::new("http://localhost:7700", Some("masterKey")); + /// # let client = Client::new("http://localhost:7700", Some("masterKey")); /// let movies = client.index("movies_wait_for_completion"); /// /// let status = movies.add_documents(&[ /// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() }, /// Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() }, /// ], None) - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// assert!(matches!(status, Task::Succeeded { .. })); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); diff --git a/src/tasks.rs b/src/tasks.rs index a11bd57b..405888b1 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -215,8 +215,9 @@ impl Task { /// Wait until Meilisearch processes a [Task], and get its status. /// - /// `interval` = The frequency at which the server should be polled. Default = 50ms - /// `timeout` = The maximum time to wait for processing to complete. Default = 5000ms + /// `interval` = The frequency at which the server should be polled. **Default = 50ms** + /// + /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. /// @@ -240,18 +241,18 @@ impl Task { /// # /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("movies_wait_for_completion"); /// /// let status = movies.add_documents(&[ /// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() }, /// Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() }, /// ], None) - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// assert!(matches!(status, Task::Succeeded { .. })); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -279,9 +280,8 @@ impl Task { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # // create the client + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let task = client.create_index("try_make_index", None).await.unwrap(); /// let index = client.wait_for_task(task, None, None).await.unwrap().try_make_index(&client).unwrap(); /// @@ -358,6 +358,7 @@ impl Task { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let task = client.create_index("is_failure", None).await.unwrap(); + /// // create an index with a conflicting uid /// let task = client /// .create_index("is_failure", None) /// .await @@ -387,12 +388,12 @@ impl Task { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let task = client - /// .create_index("is_success", None) - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .create_index("is_success", None) + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// assert!(task.is_success()); /// # task.try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -416,10 +417,11 @@ impl Task { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let task_info = client - /// .create_index("is_pending", None) - /// .await - /// .unwrap(); + /// .create_index("is_pending", None) + /// .await + /// .unwrap(); /// let task = client.get_task(task_info).await.unwrap(); + /// /// assert!(task.is_pending()); /// # task.wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -441,10 +443,10 @@ impl AsRef for Task { #[derive(Debug, Serialize, Clone)] pub struct TasksPaginationFilters { - // Maximum number of tasks to return + // Maximum number of tasks to return. #[serde(skip_serializing_if = "Option::is_none")] limit: Option, - // The first task uid that should be returned + // The first task uid that should be returned. #[serde(skip_serializing_if = "Option::is_none")] from: Option, } @@ -473,10 +475,10 @@ pub struct TasksQuery<'a, T> { // Types array to only retrieve the tasks with these [TaskType]. #[serde(skip_serializing_if = "Option::is_none", rename = "types")] task_types: Option>, - // Uids of the tasks to retrieve + // Uids of the tasks to retrieve. #[serde(skip_serializing_if = "Option::is_none")] uids: Option>, - // Uids of the tasks that canceled other tasks + // Uids of the tasks that canceled other tasks. #[serde(skip_serializing_if = "Option::is_none")] canceled_by: Option>, // Date to retrieve all tasks that were enqueued before it. From e908391906413d1a923ef0da3172817d50055be3 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 13:34:16 -0400 Subject: [PATCH 3/7] search through indexes --- src/indexes.rs | 196 +++++++++++++++++++++++++------------------------ src/key.rs | 68 +++++++++-------- src/lib.rs | 2 +- src/search.rs | 107 ++++++++++++++++----------- 4 files changed, 201 insertions(+), 172 deletions(-) diff --git a/src/indexes.rs b/src/indexes.rs index 0dc973d6..701f3617 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -24,20 +24,20 @@ use time::OffsetDateTime; /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { -/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); +/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// /// // get the index called movies or create it if it does not exist /// let movies = client -/// .create_index("index", None) -/// .await -/// .unwrap() -/// // We wait for the task to execute until completion -/// .wait_for_completion(&client, None, None) -/// .await -/// .unwrap() -/// // Once the task finished, we try to create an `Index` out of it -/// .try_make_index(&client) -/// .unwrap(); +/// .create_index("index", None) +/// .await +/// .unwrap() +/// // We wait for the task to execute until completion +/// .wait_for_completion(&client, None, None) +/// .await +/// .unwrap() +/// // Once the task finished, we try to create an `Index` out of it +/// .try_make_index(&client) +/// .unwrap(); /// /// assert_eq!(movies.as_ref(), "index"); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -52,7 +52,7 @@ use time::OffsetDateTime; /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { -/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); +/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// /// // Meilisearch would be able to create the index if it does not exist during: /// // - the documents addition (add and update routes) @@ -85,7 +85,7 @@ impl Index { updated_at: None, } } - /// Internal Function to create an [Index] from `serde_json::Value` and [Client] + /// Internal Function to create an [Index] from `serde_json::Value` and [Client]. pub(crate) fn from_value(raw_index: serde_json::Value, client: Client) -> Result { #[derive(Deserialize, Debug)] #[allow(non_snake_case)] @@ -131,16 +131,17 @@ impl Index { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// + /// # /// index.primary_key = Some("special_id".to_string()); /// let task = index.update() - /// .await - /// .unwrap() - /// .wait_for_completion(&client, None, None) - /// .await - /// .unwrap(); + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await + /// .unwrap(); /// /// let index = client.get_index("index_update").await.unwrap(); + /// /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -166,12 +167,13 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("delete", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// /// // get the index named "movies" and delete it /// let index = client.index("delete"); /// let task = index.delete().await.unwrap(); + /// /// client.wait_for_task(task, None, None).await.unwrap(); /// # }); /// ``` @@ -185,15 +187,15 @@ impl Index { .await } - /// Search for documents matching a specific query in the index.\ + /// Search for documents matching a specific query in the index. + /// /// See also [Index::search]. /// /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, search::*}; - /// /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); @@ -203,9 +205,8 @@ impl Index { /// name: String, /// description: String, /// } - /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("execute_query"); /// /// // add some documents @@ -213,7 +214,8 @@ impl Index { /// /// let query = SearchQuery::new(&movies).with_query("Interstellar").with_limit(5).build(); /// let results = movies.execute_query::(&query).await.unwrap(); - /// assert!(results.hits.len()>0); + /// + /// assert!(results.hits.len() > 0); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -230,15 +232,15 @@ impl Index { .await } - /// Search for documents matching a specific query in the index.\ + /// Search for documents matching a specific query in the index. + /// /// See also [Index::execute_query]. /// /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, search::*}; - /// /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); @@ -250,10 +252,9 @@ impl Index { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut movies = client.index("search"); - /// - /// // add some documents + /// # // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// /// let results = movies.search() @@ -263,7 +264,7 @@ impl Index { /// .await /// .unwrap(); /// - /// assert!(results.hits.len()>0); + /// assert!(results.hits.len() > 0); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -272,15 +273,14 @@ impl Index { } /// Get one document using its unique id. + /// /// Serde is needed. Add `serde = {version="1.0", features=["derive"]}` in the dependencies section of your Cargo.toml. /// /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # 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"); @@ -292,7 +292,7 @@ impl Index { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("get_document"); /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// @@ -336,18 +336,17 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// # futures::executor::block_on(async move { /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObject { /// id: String, /// kind: String, /// } + /// /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObjectReduced { /// id: String, /// } - /// /// # let index = client.index("document_query_execute"); /// # index.add_or_replace(&[MyObject{id:"1".to_string(), kind:String::from("a kind")},MyObject{id:"2".to_string(), kind:String::from("some kind")}], None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// @@ -388,26 +387,21 @@ impl Index { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # 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"); /// # - /// - /// #[derive(Serialize, Deserialize, Debug)] - /// # #[derive(PartialEq)] + /// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// struct Movie { /// name: String, /// description: String, /// } /// - /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("get_documents"); - /// /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// /// // retrieve movies (you have to put some movies in the index before) @@ -432,17 +426,17 @@ impl Index { } /// Get documents by batch with parameters. + /// + /// # Example + /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, documents::*}; /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); - /// # - /// - /// #[derive(Serialize, Deserialize, Debug)] - /// # #[derive(PartialEq)] + /// # + /// #[derive(Serialize, Deserialize, PartialEq Debug)] /// struct Movie { /// name: String, /// description: String, @@ -452,12 +446,10 @@ impl Index { /// struct ReturnedMovie { /// name: String, /// } - /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// /// let movie_index = client.index("get_documents_with"); - /// /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// /// let mut query = DocumentsQuery::new(&movie_index); @@ -498,8 +490,7 @@ impl Index { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*}; /// # use std::thread::sleep; /// # use std::time::Duration; @@ -514,7 +505,7 @@ impl Index { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_or_replace"); /// /// let task = movie_index.add_or_replace(&[ @@ -566,6 +557,7 @@ impl Index { } /// Add a raw and unchecked payload to meilisearch. + /// /// This can be useful if your application is only forwarding data from other sources. /// /// If you send an already existing document (same id) the **whole existing document** will be overwritten by the new document. @@ -576,8 +568,7 @@ impl Index { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*}; /// # use std::thread::sleep; /// # use std::time::Duration; @@ -585,7 +576,7 @@ impl Index { /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_or_replace_unchecked_payload"); /// /// let task = movie_index.add_or_replace_unchecked_payload( @@ -651,8 +642,7 @@ impl Index { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::client::*; /// # use std::thread::sleep; /// # use std::time::Duration; @@ -665,9 +655,9 @@ impl Index { /// name: String, /// description: String, /// } - /// + /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_or_update"); /// /// let task = movie_index.add_or_update(&[ @@ -722,6 +712,7 @@ impl Index { } /// Add a raw and unchecked payload to meilisearch. + /// /// This can be useful if your application is only forwarding data from other sources. /// /// If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. @@ -732,8 +723,7 @@ impl Index { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; - /// + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*}; /// # use std::thread::sleep; /// # use std::time::Duration; @@ -741,7 +731,7 @@ impl Index { /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_or_replace_unchecked_payload"); /// /// let task = movie_index.add_or_update_unchecked_payload( @@ -749,11 +739,12 @@ impl Index { /// { "id": 2, "body": "catto" }"#.as_bytes(), /// "application/x-ndjson", /// Some("id"), - /// ).await.unwrap(); + /// ).await.unwrap(); /// // Meilisearch may take some time to execute the request so we are going to wait till it's completed /// client.wait_for_task(task, None, None).await.unwrap(); /// /// let movies = movie_index.get_documents::().await.unwrap(); + /// /// assert!(movies.results.len() == 2); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -788,7 +779,7 @@ impl Index { .await } - /// Delete all documents in the index. + /// Delete all documents in the [Index]. /// /// # Example /// @@ -956,12 +947,11 @@ impl Index { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// # // create the client /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("fetch_info", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// // get the information of the index named "fetch_info" /// let mut idx = client.index("fetch_info"); /// idx.fetch_info().await.unwrap(); + /// /// println!("{idx:?}"); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -989,7 +979,14 @@ impl Index { /// # futures::executor::block_on(async move { /// # // create the client /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let mut index = client.create_index("get_primary_key", Some("id")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); + /// let mut index = client.create_index("get_primary_key", Some("id")) + /// .await + /// .unwrap() + /// .wait_for_completion(&client, None, None) + /// .await.unwrap() + /// .try_make_index(&client) + /// .unwrap(); + /// /// let primary_key = index.get_primary_key().await.unwrap(); /// /// assert_eq!(primary_key, Some("id")); @@ -1023,7 +1020,7 @@ impl Index { /// # /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("get_task"); /// /// let task = movies.add_documents(&[ @@ -1041,7 +1038,7 @@ impl Index { /// Task::Succeeded { content } => content.uid, /// }; /// - /// # assert_eq!(task.get_task_uid(), from_index); + /// assert_eq!(task.get_task_uid(), from_index); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1071,7 +1068,7 @@ impl Index { /// # let index = client.create_index("get_tasks", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let tasks = index.get_tasks().await.unwrap(); /// - /// # assert!(tasks.results.len() > 0); + /// assert!(tasks.results.len() > 0); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1098,9 +1095,10 @@ impl Index { /// # let index = client.create_index("get_tasks_with", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let mut query = TasksSearchQuery::new(&client); /// query.with_index_uids(["none_existant"]); + /// /// let tasks = index.get_tasks_with(&query).await.unwrap(); /// - /// # assert!(tasks.results.len() > 0); + /// assert!(tasks.results.len() > 0); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1128,7 +1126,8 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_stats", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let stats = index.get_stats().await.unwrap(); - /// # assert_eq!(stats.is_indexing, false); + /// + /// assert_eq!(stats.is_indexing, false); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1144,8 +1143,9 @@ impl Index { /// Wait until Meilisearch processes a [Task], and get its status. /// - /// `interval` = The frequency at which the server should be polled. Default = 50ms - /// `timeout` = The maximum time to wait for processing to complete. Default = 5000ms + /// `interval` = The frequency at which the server should be polled. **Default = 50ms** + /// + /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. /// @@ -1179,7 +1179,7 @@ impl Index { /// /// let status = movies.wait_for_task(task, None, None).await.unwrap(); /// - /// # assert!(matches!(status, Task::Succeeded { .. })); + /// assert!(matches!(status, Task::Succeeded { .. })); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1198,7 +1198,7 @@ impl Index { /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch /// - /// `batch_size` is 1000 by default + /// **`batch_size` is 1000 by default** /// /// # Example /// @@ -1239,7 +1239,8 @@ impl Index { /// client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap(); /// /// let movies = movie_index.get_documents::().await.unwrap(); - /// # assert!(movies.results.len() >= 3); + /// + /// assert!(movies.results.len() >= 3); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, /// # None).await.unwrap(); /// # }); @@ -1263,7 +1264,7 @@ impl Index { /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch /// - /// `batch_size` is 1000 by default + /// **`batch_size` is 1000 by default** /// /// # Example /// @@ -1327,7 +1328,7 @@ impl Index { /// /// let movies_updated = movie_index.get_documents::().await.unwrap(); /// - /// # assert!(movies_updated.results.len() >= 3); + /// assert!(movies_updated.results.len() >= 3); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, /// # None).await.unwrap(); /// # }); @@ -1358,10 +1359,8 @@ impl AsRef for Index { /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*, task_info::*, tasks::{Task, SucceededTask}}; -/// /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); -/// /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client @@ -1384,7 +1383,8 @@ impl AsRef for Index { /// .unwrap(); /// /// let index = client.get_index("index_updater").await.unwrap(); -/// # assert_eq!(index.primary_key, Some("special_id".to_string())); +/// +/// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1438,7 +1438,8 @@ impl<'a> IndexUpdater<'a> { /// .unwrap(); /// /// let index = client.get_index("index_updater_with_primary_key").await.unwrap(); - /// # assert_eq!(index.primary_key, Some("special_id".to_string())); + /// + /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1479,7 +1480,8 @@ impl<'a> IndexUpdater<'a> { /// .unwrap(); /// /// let index = client.get_index("index_updater_execute").await.unwrap(); - /// # assert_eq!(index.primary_key, Some("special_id".to_string())); + /// + /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1536,14 +1538,14 @@ pub struct IndexStats { /// # .wait_for_completion(&client, None, None) /// # .await /// # .unwrap() -/// # // Once the task finished, we try to create an `Index` out of it +/// # // Once the task finished, we try to create an `Index` out of it. /// # .try_make_index(&client) /// # .unwrap(); /// let mut indexes = IndexesQuery::new(&client) /// .with_limit(1) /// .execute().await.unwrap(); /// -/// # assert_eq!(indexes.results.len(), 1); +/// assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1568,7 +1570,7 @@ pub struct IndexesQuery<'a> { /// /// Example: If you don't want to get more than two indexes, set limit to `2`. /// - /// Default: `20` + /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, } @@ -1608,7 +1610,7 @@ impl<'a> IndexesQuery<'a> { /// .with_offset(1) /// .execute().await.unwrap(); /// - /// # assert_eq!(indexes.offset, 1); + /// assert_eq!(indexes.offset, 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1643,7 +1645,7 @@ impl<'a> IndexesQuery<'a> { /// .with_limit(1) /// .execute().await.unwrap(); /// - /// # assert_eq!(indexes.results.len(), 1); + /// assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` @@ -1677,7 +1679,7 @@ impl<'a> IndexesQuery<'a> { /// .with_limit(1) /// .execute().await.unwrap(); /// - /// # assert_eq!(indexes.results.len(), 1); + /// assert_eq!(indexes.results.len(), 1); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` diff --git a/src/key.rs b/src/key.rs index 81b9c1af..ce2d4895 100644 --- a/src/key.rs +++ b/src/key.rs @@ -28,7 +28,7 @@ pub struct Key { } impl Key { - /// Update the description of the key. + /// Update the description of the [Key]. /// /// # Example /// @@ -47,7 +47,7 @@ impl Key { /// .with_description(&description) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(key.description, Some(description)); + /// assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -56,7 +56,7 @@ impl Key { self } - /// Update the name of the key. + /// Update the name of the [Key]. /// /// # Example /// @@ -68,14 +68,17 @@ impl Key { /// # /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// let name = "lovely key".to_string(); - /// let mut key = KeyBuilder::new() - /// .with_action(Action::DocumentsAdd) - /// .with_index("*") - /// .execute(&client).await.unwrap(); - /// - /// key.with_name(&name); - /// # assert_eq!(key.name, Some(name)); + /// let name = "lovely key".to_string(); + /// let mut key = KeyBuilder::new() + /// .with_action(Action::DocumentsAdd) + /// .with_index("*") + /// .execute(&client) + /// .await + /// .unwrap(); + /// + /// key.with_name(&name); + /// + /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -97,12 +100,16 @@ impl Key { /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut key = KeyBuilder::new() - /// .execute(&client).await.unwrap(); + /// .execute(&client) + /// .await + /// .unwrap(); + /// /// let description = "My not so little lovely test key".to_string(); /// key.with_description(&description); + /// /// let key = key.update(&client).await.unwrap(); /// - /// # assert_eq!(key.description, Some(description)); + /// assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -173,7 +180,7 @@ impl KeyUpdater { } } - /// Update the description of the key. + /// Update the description of the [Key]. /// /// # Example /// @@ -197,7 +204,7 @@ impl KeyUpdater { /// .await /// .unwrap(); /// - /// # assert_eq!(key_update.description, Some(description)); + /// assert_eq!(key_update.description, Some(description)); /// # client.delete_key(key_update).await.unwrap(); /// # }); /// ``` @@ -206,7 +213,7 @@ impl KeyUpdater { self } - /// Update the name of the key. + /// Update the name of the [Key]. /// /// # Example /// @@ -230,7 +237,7 @@ impl KeyUpdater { /// .await /// .unwrap(); /// - /// # assert_eq!(key_update.name, Some(name)); + /// assert_eq!(key_update.name, Some(name)); /// # client.delete_key(key_update).await.unwrap(); /// # }); /// ``` @@ -258,7 +265,7 @@ impl KeyUpdater { /// let mut key_update = KeyUpdater::new(&key.key); /// key_update.with_description(&description).execute(&client).await; /// - /// # assert_eq!(key_update.description, Some(description)); + /// assert_eq!(key_update.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -296,7 +303,8 @@ pub struct KeysQuery { /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// Default: `20` + /// + /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, } @@ -330,7 +338,7 @@ impl KeysQuery { /// .with_offset(1) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(keys.offset, 1); + /// assert_eq!(keys.offset, 1); /// # }); /// ``` pub fn with_offset(&mut self, offset: usize) -> &mut KeysQuery { @@ -354,7 +362,7 @@ impl KeysQuery { /// .with_limit(1) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(keys.results.len(), 1); + /// assert_eq!(keys.results.len(), 1); /// # }); /// ``` pub fn with_limit(&mut self, limit: usize) -> &mut KeysQuery { @@ -378,7 +386,7 @@ impl KeysQuery { /// .with_limit(1) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(keys.results.len(), 1); + /// assert_eq!(keys.results.len(), 1); /// # }); /// ``` pub async fn execute(&self, client: &Client) -> Result { @@ -405,7 +413,7 @@ impl KeysQuery { /// .with_description(&description) /// .execute(&client).await.unwrap(); /// -/// # assert_eq!(key.description, Some(description)); +/// assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -528,7 +536,7 @@ impl KeyBuilder { self } - /// Add a description to the key. + /// Add a description to the [Key]. /// /// # Example /// @@ -545,7 +553,7 @@ impl KeyBuilder { /// .with_description(&description) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(key.description, Some(description)); + /// assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -554,7 +562,7 @@ impl KeyBuilder { self } - /// Add a name to the key. + /// Add a name to the [Key]. /// /// # Example /// @@ -571,7 +579,7 @@ impl KeyBuilder { /// .with_name(&name) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(key.name, Some(name)); + /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -580,7 +588,7 @@ impl KeyBuilder { self } - /// Add an uid to the key. + /// Add an uid to the [Key]. /// /// # Example /// @@ -597,7 +605,7 @@ impl KeyBuilder { /// .with_uid(&uid) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(key.uid, uid); + /// assert_eq!(key.uid, uid); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` @@ -623,7 +631,7 @@ impl KeyBuilder { /// .with_description(&description) /// .execute(&client).await.unwrap(); /// - /// # assert_eq!(key.description, Some(description)); + /// assert_eq!(key.description, Some(description)); /// # client.delete_key(key).await.unwrap(); /// # }); /// ``` diff --git a/src/lib.rs b/src/lib.rs index 9b401adb..4087068b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,7 +252,7 @@ mod utils; pub use client::*; #[cfg(test)] -/// Support for the `IndexConfig` derive proc macro in the crate's tests +/// Support for the `IndexConfig` derive proc macro in the crate's tests. extern crate self as meilisearch_sdk; /// Can't assume that the user of proc_macro will have access to `async_trait` crate. So exporting the `async-trait` crate from `meilisearch_sdk` in a hidden module. #[doc(hidden)] diff --git a/src/search.rs b/src/search.rs index dac83ecc..7f68e85f 100644 --- a/src/search.rs +++ b/src/search.rs @@ -32,6 +32,7 @@ pub enum MatchingStrategies { } /// A single result. +/// /// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches. #[derive(Deserialize, Debug, Clone)] pub struct SearchResult { @@ -56,31 +57,31 @@ pub struct FacetStats { #[serde(rename_all = "camelCase")] /// A struct containing search results and other information about the search. pub struct SearchResults { - /// Results of the query + /// Results of the query. pub hits: Vec>, - /// Number of documents skipped + /// Number of documents skipped. pub offset: Option, - /// Number of results returned + /// Number of results returned. pub limit: Option, - /// Estimated total number of matches + /// Estimated total number of matches. pub estimated_total_hits: Option, // Current page number pub page: Option, - // Maximum number of hits in a page + // Maximum number of hits in a page. pub hits_per_page: Option, - // Exhaustive number of matches + // Exhaustive number of matches. pub total_hits: Option, - // Exhaustive number of pages + // Exhaustive number of pages. pub total_pages: Option, - /// Distribution of the given facets + /// Distribution of the given facets. pub facet_distribution: Option>>, /// facet stats of the numerical facets requested in the `facet` search parameter. pub facet_stats: Option>, - /// Processing time of the query + /// Processing time of the query. pub processing_time_ms: usize, - /// Query originating the response + /// Query originating the response. pub query: String, - /// Index uid on which the search was made + /// Index uid on which the search was made. pub index_uid: Option, } @@ -119,25 +120,28 @@ fn serialize_attributes_to_crop_with_wildcard( } /// Some list fields in a `SearchQuery` can be set to a wildcard value. +/// /// This structure allows you to choose between the wildcard value and an exhaustive list of selectors. #[derive(Debug, Clone)] pub enum Selectors { - /// A list of selectors + /// A list of selectors. Some(T), - /// The wildcard + /// The wildcard. All, } type AttributeToCrop<'a> = (&'a str, Option); /// A struct representing a query. +/// /// You can add search parameters using the builder syntax. +/// /// See [this page](https://docs.meilisearch.com/reference/features/search_parameters.html#query-q) for the official list and description of all parameters. /// /// # Examples /// /// ``` -/// use serde::{Serialize, Deserialize}; +/// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::Client, search::SearchQuery, indexes::Index}; /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); @@ -148,7 +152,6 @@ type AttributeToCrop<'a> = (&'a str, Option); /// name: String, /// description: String, /// } -/// /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client @@ -159,7 +162,7 @@ type AttributeToCrop<'a> = (&'a str, Option); /// # .await.unwrap() /// # .try_make_index(&client) /// # .unwrap(); -/// +/// /// let mut res = SearchQuery::new(&index) /// .with_query("space") /// .with_offset(42) @@ -197,6 +200,7 @@ pub struct SearchQuery<'a> { #[serde(rename = "q")] pub query: Option<&'a str>, /// The number of documents to skip. + /// /// If the value of the parameter `offset` is `n`, the `n` first documents (ordered by relevance) will not be returned. /// This is helpful for pagination. /// @@ -204,32 +208,37 @@ pub struct SearchQuery<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub offset: Option, /// The maximum number of documents returned. + /// /// If the value of the parameter `limit` is `n`, there will never be more than `n` documents in the response. /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// Default: `20` + /// + /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, /// The page number on which you paginate. + /// /// Pagination starts at 1. If page is 0, no results are returned. /// - /// Default: None unless `hits_per_page` is defined, in which case page is `1` + /// **Default: None unless `hits_per_page` is defined, in which case page is `1`** #[serde(skip_serializing_if = "Option::is_none")] pub page: Option, /// The maximum number of results in a page. A page can contain less results than the number of hits_per_page. /// - /// Default: None unless `page` is defined, in which case `20` + /// **Default: None unless `page` is defined, in which case `20`** #[serde(skip_serializing_if = "Option::is_none")] pub hits_per_page: Option, /// Filter applied to documents. + /// /// Read the [dedicated guide](https://docs.meilisearch.com/reference/features/filtering.html) to learn the syntax. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option>, /// Facets for which to retrieve the matching count. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. - /// Default: all attributes found in the documents. + /// + /// **Default: all attributes found in the documents.** #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "serialize_with_wildcard")] pub facets: Option>, @@ -239,11 +248,13 @@ pub struct SearchQuery<'a> { /// Attributes to display in the returned documents. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. - /// Default: all attributes found in the documents. + /// + /// **Default: all attributes found in the documents.** #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "serialize_with_wildcard")] pub attributes_to_retrieve: Option>, /// Attributes whose values have to be cropped. + /// /// Attributes are composed by the attribute name and an optional `usize` that overwrites the `crop_length` parameter. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. @@ -251,15 +262,17 @@ pub struct SearchQuery<'a> { #[serde(serialize_with = "serialize_attributes_to_crop_with_wildcard")] pub attributes_to_crop: Option]>>, /// Maximum number of words including the matched query term(s) contained in the returned cropped value(s). + /// /// See [attributes_to_crop](#structfield.attributes_to_crop). /// - /// Default: `10` + /// **Default: `10`** #[serde(skip_serializing_if = "Option::is_none")] pub crop_length: Option, /// Marker at the start and the end of a cropped value. + /// /// ex: `...middle of a crop...` /// - /// Default: `...` + /// **Default: `...`** #[serde(skip_serializing_if = "Option::is_none")] pub crop_marker: Option<&'a str>, /// Attributes whose values will contain **highlighted matching terms**. @@ -269,20 +282,22 @@ pub struct SearchQuery<'a> { #[serde(serialize_with = "serialize_with_wildcard")] pub attributes_to_highlight: Option>, /// Tag in front of a highlighted term. + /// /// ex: `hello world` /// - /// Default: `` + /// **Default: ``** #[serde(skip_serializing_if = "Option::is_none")] pub highlight_pre_tag: Option<&'a str>, /// Tag after the a highlighted term. + /// /// ex: `hello world` /// - /// Default: `` + /// **Default: ``** #[serde(skip_serializing_if = "Option::is_none")] pub highlight_post_tag: Option<&'a str>, /// Defines whether an object that contains information about the matches should be returned or not. /// - /// Default: `false` + /// **Default: `false`** #[serde(skip_serializing_if = "Option::is_none")] pub show_matches_position: Option, @@ -333,26 +348,28 @@ impl<'a> SearchQuery<'a> { self } /// Add the page number on which to paginate. + /// + /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, search::*}; /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// #[derive(Serialize, Deserialize, Debug)] - /// struct Movie { - /// name: String, - /// description: String, - /// } + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # #[derive(Serialize, Deserialize, Debug)] + /// # struct Movie { + /// # name: String, + /// # description: String, + /// # } /// # client.create_index("search_with_page", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// # let mut index = client.index("search_with_page"); + /// let mut index = client.index("search_with_page"); + /// /// let mut query = SearchQuery::new(&index); /// query.with_query("").with_page(2); - /// /// let res = query.execute::().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -363,26 +380,28 @@ impl<'a> SearchQuery<'a> { } /// Add the maximum number of results per page. + /// + /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, search::*}; /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// #[derive(Serialize, Deserialize, Debug)] - /// struct Movie { - /// name: String, - /// description: String, - /// } + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # #[derive(Serialize, Deserialize, Debug)] + /// # struct Movie { + /// # name: String, + /// # description: String, + /// # } /// # client.create_index("search_with_hits_per_page", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// # let mut index = client.index("search_with_hits_per_page"); + /// let mut index = client.index("search_with_hits_per_page"); + /// /// let mut query = SearchQuery::new(&index); /// query.with_query("").with_hits_per_page(2); - /// /// let res = query.execute::().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); From f2f85485e9f198332836a75d88ea5888cadff896 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 14:29:31 -0400 Subject: [PATCH 4/7] errors through client --- src/client.rs | 184 ++++++++++++++++++++++------------------------- src/documents.rs | 21 +++--- src/dumps.rs | 18 +++-- src/errors.rs | 6 +- src/indexes.rs | 6 +- 5 files changed, 116 insertions(+), 119 deletions(-) diff --git a/src/client.rs b/src/client.rs index 17b3c88d..f01b3351 100644 --- a/src/client.rs +++ b/src/client.rs @@ -28,17 +28,19 @@ pub struct SwapIndexes { impl Client { /// Create a client using the specified server. + /// /// Don't put a '/' at the end of the host. + /// /// In production mode, see [the documentation about authentication](https://docs.meilisearch.com/reference/features/authentication.html#authentication). + /// /// # Example /// /// ``` /// # 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"); - /// # - /// // create the client + /// let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); + /// let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); + /// /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// ``` pub fn new(host: impl Into, api_key: Option>) -> Client { @@ -82,9 +84,8 @@ impl Client { /// # Example /// /// ``` - /// use serde::{Serialize, Deserialize}; + /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, search::*}; - /// /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); @@ -96,10 +97,9 @@ impl Client { /// } /// /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut movies = client.index("search"); - /// - /// // add some documents + /// # // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// /// let search_query_1 = SearchQuery::new(&movies) @@ -132,7 +132,6 @@ impl Client { /// ``` /// # use meilisearch_sdk::{client::*}; /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); - /// // create the client /// let client = Client::new("http://doggo.dog", Some(MEILISEARCH_API_KEY)); /// /// assert_eq!(client.get_host(), "http://doggo.dog"); @@ -148,7 +147,6 @@ impl Client { /// ``` /// # use meilisearch_sdk::{client::*}; /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); - /// // create the client /// let client = Client::new(MEILISEARCH_URL, Some("doggo")); /// /// assert_eq!(client.get_api_key(), Some("doggo")); @@ -157,7 +155,7 @@ impl Client { self.api_key.as_deref() } - /// List all [Index]es with query parameters and returns values as instances of [Index]. + /// List all [Indexes](Index) with query parameters and returns values as instances of [Index]. /// /// # Example /// @@ -168,10 +166,9 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let indexes: IndexesResults = client.list_all_indexes().await.unwrap(); + /// /// println!("{:?}", indexes); /// # }); /// ``` @@ -181,7 +178,7 @@ impl Client { Ok(indexes_results) } - /// List all [Index]es and returns values as instances of [Index]. + /// List all [Indexes](Index) and returns values as instances of [Index]. /// /// # Example /// @@ -192,10 +189,10 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut query = IndexesQuery::new(&client); /// query.with_limit(1); + /// /// let indexes: IndexesResults = client.list_all_indexes_with(&query).await.unwrap(); /// /// assert_eq!(indexes.limit, 1); @@ -211,7 +208,7 @@ impl Client { Ok(indexes_results) } - /// List all [Index]es and returns as Json. + /// List all [Indexes](Index) and returns as Json. /// /// # Example /// @@ -222,10 +219,9 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let json_indexes = client.list_all_indexes_raw().await.unwrap(); + /// /// println!("{:?}", json_indexes); /// # }); /// ``` @@ -241,7 +237,7 @@ impl Client { Ok(json_indexes) } - /// List all [Index]es with query parameters and returns as Json. + /// List all [Indexes](Index) with query parameters and returns as Json. /// /// # Example /// @@ -252,11 +248,10 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut query = IndexesQuery::new(&client); /// query.with_limit(1); + /// /// let json_indexes = client.list_all_indexes_raw_with(&query).await.unwrap(); /// /// println!("{:?}", json_indexes); @@ -290,12 +285,10 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_index", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// - /// // get the index named "get_index" /// let index = client.get_index("get_index").await.unwrap(); + /// /// assert_eq!(index.as_ref(), "get_index"); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -308,6 +301,8 @@ impl Client { /// Get a raw JSON [Index], this index should already exist. /// + /// If you use it directly from an [Index], you can use the method [Index::fetch_info], which is the equivalent method from an index. + /// /// # Example /// /// ``` @@ -317,17 +312,14 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_raw_index", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); - /// - /// // get the index named "get_raw_index" /// let raw_index = client.get_raw_index("get_raw_index").await.unwrap(); + /// /// assert_eq!(raw_index.get("uid").unwrap().as_str().unwrap(), "get_raw_index"); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - /// If you use it directly from an [Index], you can use the method [Index::fetch_info], which is the equivalent method from an index. pub async fn get_raw_index(&self, uid: impl AsRef) -> Result { request::<(), (), Value>( &format!("{}/indexes/{}", self.host, uid.as_ref()), @@ -344,10 +336,10 @@ impl Client { } /// Create an [Index]. - /// + /// /// The second parameter will be used as the primary key of the new index. /// If it is not specified, Meilisearch will **try** to infer the primary key. - /// + /// /// # Example /// /// ``` @@ -357,9 +349,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // Create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// // Create a new index called movies and access it /// let task = client.create_index("create_index", None).await.unwrap(); /// @@ -394,6 +384,7 @@ impl Client { } /// Delete an index from its UID. + /// /// To delete an [Index], use the [Index::delete] method. pub async fn delete_index(&self, uid: impl AsRef) -> Result { request::<(), (), TaskInfo>( @@ -431,7 +422,7 @@ impl Client { self.list_all_indexes_raw_with(indexes_query).await } - /// Swaps a list of two [Index]'es. + /// Swaps a list of two [Indexes](Index). /// /// # Example /// @@ -442,9 +433,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// // Create the client - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let task_index_1 = client.create_index("swap_index_1", None).await.unwrap(); /// let task_index_2 = client.create_index("swap_index_2", None).await.unwrap(); /// @@ -452,14 +441,14 @@ impl Client { /// task_index_2.wait_for_completion(&client, None, None).await.unwrap(); /// /// let task = client - /// .swap_indexes([&SwapIndexes { - /// indexes: ( - /// "swap_index_1".to_string(), - /// "swap_index_2".to_string(), - /// ), - /// }]) - /// .await - /// .unwrap(); + /// .swap_indexes([&SwapIndexes { + /// indexes: ( + /// "swap_index_1".to_string(), + /// "swap_index_2".to_string(), + /// ), + /// }]) + /// .await + /// .unwrap(); /// /// # client.index("swap_index_1").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # client.index("swap_index_2").delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -481,7 +470,7 @@ impl Client { .await } - /// Get stats of all indexes. + /// Get stats of all [Indexes](Index). /// /// # Example /// @@ -492,7 +481,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let stats = client.get_stats().await.unwrap(); /// # }); /// ``` @@ -517,8 +506,9 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let health = client.health().await.unwrap(); + /// /// assert_eq!(health.status, "available"); /// # }); /// ``` @@ -532,7 +522,7 @@ impl Client { .await } - /// Get health of Meilisearch server, return true or false. + /// Get health of Meilisearch server. /// /// # Example /// @@ -543,8 +533,9 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let health = client.is_healthy().await; + /// /// assert_eq!(health, true); /// # }); /// ``` @@ -556,10 +547,9 @@ impl Client { } } - /// Get the API [Key]s from Meilisearch with parameters. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). + /// Get the API [Keys](Key) from Meilisearch with parameters. /// - /// See also [Client::create_key] and [Client::get_key]. + /// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). /// /// # Example /// @@ -570,9 +560,10 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut query = KeysQuery::new(); /// query.with_limit(1); + /// /// let keys = client.get_keys_with(&query).await.unwrap(); /// /// assert_eq!(keys.results.len(), 1); @@ -590,10 +581,9 @@ impl Client { Ok(keys) } - /// Get the API [Key]s from Meilisearch. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). + /// Get the API [Keys](Key) from Meilisearch. /// - /// See also [Client::create_key] and [Client::get_key]. + /// See [Client::create_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys). /// /// # Example /// @@ -604,7 +594,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let keys = client.get_keys().await.unwrap(); /// /// assert_eq!(keys.limit, 20); @@ -623,9 +613,8 @@ impl Client { } /// Get one API [Key] from Meilisearch. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key). /// - /// See also [Client::create_key] and [Client::get_keys]. + /// See also [Client::create_key], [Client::get_keys], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#get-one-key). /// /// # Example /// @@ -636,11 +625,10 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let key = client.get_keys().await.unwrap().results.into_iter() - /// .find(|k| k.name.as_ref().map_or(false, |name| name.starts_with("Default Search API Key"))) - /// .unwrap(); - /// + /// # .find(|k| k.name.as_ref().map_or(false, |name| name.starts_with("Default Search API Key"))) + /// # .unwrap(); /// let key = client.get_key(key).await.unwrap(); /// /// assert_eq!(key.name, Some("Default Search API Key".to_string())); @@ -657,9 +645,8 @@ impl Client { } /// Delete an API [Key] from Meilisearch. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#delete-a-key). /// - /// See also [Client::create_key], [Client::update_key] and [Client::get_key]. + /// See also [Client::create_key], [Client::update_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#delete-a-key). /// /// # Example /// @@ -670,7 +657,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let key = KeyBuilder::new(); /// let key = client.create_key(key).await.unwrap(); /// let inner_key = key.key.clone(); @@ -678,6 +665,7 @@ impl Client { /// client.delete_key(key).await.unwrap(); /// /// let keys = client.get_keys().await.unwrap(); + /// /// assert!(keys.results.iter().all(|key| key.key != inner_key)); /// # }); /// ``` @@ -692,9 +680,8 @@ impl Client { } /// Create an API [Key] in Meilisearch. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#create-a-key). /// - /// See also [Client::update_key], [Client::delete_key] and [Client::get_key]. + /// See also [Client::update_key], [Client::delete_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#create-a-key). /// /// # Example /// @@ -705,12 +692,13 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let name = "create_key".to_string(); /// let mut key = KeyBuilder::new(); /// key.with_name(&name); /// /// let key = client.create_key(key).await.unwrap(); + /// /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); @@ -729,9 +717,8 @@ impl Client { } /// Update an API [Key] in Meilisearch. - /// See the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#update-a-key). /// - /// See also [Client::create_key], [Client::delete_key] and [Client::get_key]. + /// See also [Client::create_key], [Client::delete_key], [Client::get_key], and the [meilisearch documentation](https://docs.meilisearch.com/reference/api/keys.html#update-a-key). /// /// # Example /// @@ -742,14 +729,16 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let new_key = KeyBuilder::new(); - /// let name = "my name".to_string(); /// let mut new_key = client.create_key(new_key).await.unwrap(); /// let mut key_update = KeyUpdater::new(new_key); + /// + /// let name = "my name".to_string(); /// key_update.with_name(&name); /// /// let key = client.update_key(key_update).await.unwrap(); + /// /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); @@ -778,7 +767,7 @@ impl Client { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let version = client.get_version().await.unwrap(); /// # }); /// ``` @@ -794,8 +783,9 @@ impl Client { /// Wait until Meilisearch processes a [Task], and get its status. /// - /// `interval` = The frequency at which the server should be polled. Default = 50ms - /// `timeout` = The maximum time to wait for processing to complete. Default = 5000ms + /// `interval` = The frequency at which the server should be polled. **Default = 50ms** + /// + /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. /// @@ -820,7 +810,7 @@ impl Client { /// # /// # /// # futures::executor::block_on(async move { - /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); + /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movies = client.index("movies_client_wait_for_task"); /// /// let task = movies.add_documents(&[ @@ -879,6 +869,7 @@ impl Client { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("movies_get_task", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let task = index.delete_all_documents().await.unwrap(); + /// /// let task = client.get_task(task).await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -905,9 +896,9 @@ impl Client { /// # /// # futures::executor::block_on(async move { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// let mut query = tasks::TasksSearchQuery::new(&client); /// query.with_index_uids(["get_tasks_with"]); + /// /// let tasks = client.get_tasks_with(&query).await.unwrap(); /// # }); /// ``` @@ -926,7 +917,7 @@ impl Client { Ok(tasks) } - /// Cancel tasks with filters [TasksCancelQuery] + /// Cancel tasks with filters [TasksCancelQuery]. /// /// # Example /// @@ -938,7 +929,6 @@ impl Client { /// # /// # futures::executor::block_on(async move { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// let mut query = tasks::TasksCancelQuery::new(&client); /// query.with_index_uids(["movies"]); /// @@ -963,7 +953,7 @@ impl Client { Ok(tasks) } - /// Delete tasks with filters [TasksDeleteQuery] + /// Delete tasks with filters [TasksDeleteQuery]. /// /// # Example /// @@ -975,7 +965,6 @@ impl Client { /// # /// # futures::executor::block_on(async move { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// let mut query = tasks::TasksDeleteQuery::new(&client); /// query.with_index_uids(["movies"]); /// @@ -1011,7 +1000,7 @@ impl Client { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let tasks = client.get_tasks().await.unwrap(); /// - /// # assert!(tasks.results.len() > 0); + /// assert!(tasks.results.len() > 0); /// # }); /// ``` pub async fn get_tasks(&self) -> Result { @@ -1040,6 +1029,7 @@ impl Client { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let api_key_uid = "76cf8b87-fd12-4688-ad34-260d930ca4f4".to_string(); /// let token = client.generate_tenant_token(api_key_uid, serde_json::json!(["*"]), None, None).unwrap(); + /// /// let client = client::Client::new(MEILISEARCH_URL, Some(token)); /// # }); /// ``` @@ -1075,12 +1065,12 @@ pub struct ClientStats { /// Health of the Meilisearch server. /// -/// Example: +/// # Example /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*, errors::Error}; /// Health { -/// status: "available".to_string(), +/// status: "available".to_string(), /// }; /// ``` #[derive(Deserialize)] @@ -1090,14 +1080,14 @@ pub struct Health { /// Version of a Meilisearch server. /// -/// Example: +/// # Example /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*, errors::Error}; /// Version { -/// commit_sha: "b46889b5f0f2f8b91438a08a358ba8f05fc09fc1".to_string(), -/// commit_date: "2019-11-15T09:51:54.278247+00:00".to_string(), -/// pkg_version: "0.1.1".to_string(), +/// commit_sha: "b46889b5f0f2f8b91438a08a358ba8f05fc09fc1".to_string(), +/// commit_date: "2019-11-15T09:51:54.278247+00:00".to_string(), +/// pkg_version: "0.1.1".to_string(), /// }; /// ``` #[derive(Deserialize)] diff --git a/src/documents.rs b/src/documents.rs index a7a6a168..b291cc0e 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -125,22 +125,24 @@ impl<'a> DocumentQuery<'a> { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// # futures::executor::block_on(async move { /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObject { /// id: String, /// kind: String, /// } + /// /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObjectReduced { /// id: String, /// } - /// /// # let index = client.index("document_query_execute"); /// # index.add_or_replace(&[MyObject{id:"1".to_string(), kind:String::from("a kind")},MyObject{id:"2".to_string(), kind:String::from("some kind")}], None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// - /// let document = DocumentQuery::new(&index).with_fields(["id"]).execute::("1").await.unwrap(); + /// let document = DocumentQuery::new(&index).with_fields(["id"]) + /// .execute::("1") + /// .await + /// .unwrap(); /// /// assert_eq!( /// document, @@ -162,6 +164,7 @@ pub struct DocumentsQuery<'a> { pub index: &'a Index, /// The number of documents to skip. + /// /// If the value of the parameter `offset` is `n`, the `n` first documents will not be returned. /// This is helpful for pagination. /// @@ -174,7 +177,8 @@ pub struct DocumentsQuery<'a> { /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// Default: `20` + /// + /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, @@ -272,7 +276,6 @@ impl<'a> DocumentsQuery<'a> { /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); - /// /// # futures::executor::block_on(async move { /// # let index = client.create_index("documents_query_execute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// #[derive(Debug, Serialize, Deserialize, PartialEq)] @@ -283,10 +286,10 @@ impl<'a> DocumentsQuery<'a> { /// let index = client.index("documents_query_execute"); /// /// let document = DocumentsQuery::new(&index) - /// .with_offset(1) - /// .execute::() - /// .await - /// .unwrap(); + /// .with_offset(1) + /// .execute::() + /// .await + /// .unwrap(); /// /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); diff --git a/src/dumps.rs b/src/dumps.rs index 61bc4dff..76608c6e 100644 --- a/src/dumps.rs +++ b/src/dumps.rs @@ -1,15 +1,17 @@ //! The `dumps` module allows the creation of database dumps. -//! Dumps are `.dump` files that can be used to launch Meilisearch. -//! Dumps are compatible between Meilisearch versions. +//! +//! - Dumps are `.dump` files that can be used to launch Meilisearch. +//! +//! - Dumps are compatible between Meilisearch versions. //! -//! Creating a dump is also referred to as exporting it, whereas launching Meilisearch with a dump is referred to as importing it. +//! - Creating a dump is also referred to as exporting it, whereas launching Meilisearch with a dump is referred to as importing it. //! -//! During a [dump export](Client::create_dump), all [indexes](crate::indexes::Index) of the current instance are exported—together with their documents and settings—and saved as a single `.dump` file. +//! - During a [dump export](Client::create_dump), all [indexes](crate::indexes::Index) of the current instance are exported—together with their documents and settings—and saved as a single `.dump` file. //! -//! During a dump import, all indexes contained in the indicated `.dump` file are imported along with their associated documents and [settings](crate::settings::Settings). +//! - During a dump import, all indexes contained in the indicated `.dump` file are imported along with their associated documents and [settings](crate::settings::Settings). //! Any existing [index](crate::indexes::Index) with the same uid as an index in the dump file will be overwritten. //! -//! Dump imports are [performed at launch](https://docs.meilisearch.com/reference/features/configuration.html#import-dump) using an option. +//! - Dump imports are [performed at launch](https://docs.meilisearch.com/reference/features/configuration.html#import-dump) using an option. //! [Batch size](https://docs.meilisearch.com/reference/features/configuration.html#dump-batch-size) can also be set at this time. //! //! # Example @@ -23,7 +25,7 @@ //! # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); //! # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); //! # -//! let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); +//! # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); //! //! // Create a dump //! let task_info = client.create_dump().await.unwrap(); @@ -43,6 +45,7 @@ use crate::{client::Client, errors::Error, request::*, task_info::TaskInfo}; /// See the [dumps](crate::dumps) module. impl Client { /// Triggers a dump creation process. + /// /// Once the process is complete, a dump is created in the [dumps directory](https://docs.meilisearch.com/reference/features/configuration.html#dumps-destination). /// If the dumps directory does not exist yet, it will be created. /// @@ -60,6 +63,7 @@ impl Client { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # /// let task_info = client.create_dump().await.unwrap(); + /// /// assert!(matches!( /// task_info, /// TaskInfo { diff --git a/src/errors.rs b/src/errors.rs index fc891b6d..ce6a4efb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -7,6 +7,7 @@ use thiserror::Error; #[non_exhaustive] pub enum Error { /// The exhaustive list of Meilisearch errors: + /// /// Also check out: #[error(transparent)] Meilisearch(#[from] MeilisearchError), @@ -21,6 +22,7 @@ pub enum Error { #[error("A task did not succeed in time.")] Timeout, /// This Meilisearch SDK generated an invalid request (which was not sent). + /// /// It probably comes from an invalid API key resulting in an invalid HTTP header. #[error("Unable to generate a valid HTTP request. It probably comes from an invalid API key.")] InvalidRequest, @@ -29,6 +31,7 @@ pub enum Error { #[error("You need to provide an api key to use the `{0}` method.")] CantUseWithoutApiKey(String), /// It is not possible to generate a tenant token with a invalid api key. + /// /// Empty strings or with less than 8 characters are considered invalid. #[error("The provided api_key is invalid.")] TenantTokensInvalidApiKey, @@ -73,8 +76,7 @@ pub struct MeilisearchError { /// . #[serde(rename = "code")] pub error_code: ErrorCode, - /// The type of error (invalid request, internal error, or authentication - /// error) + /// The type of error (invalid request, internal error, or authentication error) #[serde(rename = "type")] pub error_type: ErrorType, /// A link to the Meilisearch documentation for an error. diff --git a/src/indexes.rs b/src/indexes.rs index 701f3617..5b67c761 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -937,6 +937,8 @@ impl Index { } /// Fetch the information of the index as a raw JSON [Index], this index should already exist. + /// + /// If you use it directly from the [Client], you can use the method [Client::get_raw_index], which is the equivalent method from the client. /// /// # Example /// @@ -956,10 +958,6 @@ impl Index { /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); /// ``` - /// - /// # Note - /// - /// If you use it directly from the [Client], you can use the method [Client::get_raw_index], which is the equivalent method from the client. pub async fn fetch_info(&mut self) -> Result<(), Error> { let v = self.client.get_raw_index(&self.uid).await?; *self = Index::from_value(v, self.client.clone())?; From c1d9f0f75c2ed430a6634b61bd1e0087bd3bd157 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 14:36:03 -0400 Subject: [PATCH 5/7] app-wide checking for 4 spaces rule (clippy) ///\s{4}[a-zA-Z0-9] --- src/documents.rs | 4 ++-- src/indexes.rs | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/documents.rs b/src/documents.rs index b291cc0e..5aba3538 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -145,8 +145,8 @@ impl<'a> DocumentQuery<'a> { /// .unwrap(); /// /// assert_eq!( - /// document, - /// MyObjectReduced { id: "1".to_string() } + /// document, + /// MyObjectReduced { id: "1".to_string() } /// ); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); diff --git a/src/indexes.rs b/src/indexes.rs index 5b67c761..bc66cab8 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -287,8 +287,8 @@ impl Index { /// # /// #[derive(Serialize, Deserialize, Debug, PartialEq)] /// struct Movie { - /// name: String, - /// description: String + /// name: String, + /// description: String /// } /// /// # futures::executor::block_on(async move { @@ -356,8 +356,8 @@ impl Index { /// let document = index.get_document_with::("1", &document_query).await.unwrap(); /// /// assert_eq!( - /// document, - /// MyObjectReduced { id: "1".to_string() } + /// document, + /// MyObjectReduced { id: "1".to_string() } /// ); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -395,8 +395,8 @@ impl Index { /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// struct Movie { - /// name: String, - /// description: String, + /// name: String, + /// description: String, /// } /// /// # futures::executor::block_on(async move { @@ -438,13 +438,13 @@ impl Index { /// # /// #[derive(Serialize, Deserialize, PartialEq Debug)] /// struct Movie { - /// name: String, - /// description: String, + /// name: String, + /// description: String, /// } /// /// #[derive(Deserialize, Debug, PartialEq)] /// struct ReturnedMovie { - /// name: String, + /// name: String, /// } /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); @@ -500,8 +500,8 @@ impl Index { /// # /// #[derive(Serialize, Deserialize, Debug)] /// struct Movie { - /// name: String, - /// description: String, + /// name: String, + /// description: String, /// } /// /// # futures::executor::block_on(async move { @@ -652,8 +652,8 @@ impl Index { /// # /// #[derive(Serialize, Deserialize, Debug)] /// struct Movie { - /// name: String, - /// description: String, + /// name: String, + /// description: String, /// } /// /// # futures::executor::block_on(async move { From fb8742762b1d8e294a52bb1dd17f38ce576a7dc8 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Wed, 5 Apr 2023 15:50:38 -0400 Subject: [PATCH 6/7] missed comma --- src/indexes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indexes.rs b/src/indexes.rs index bc66cab8..7618d32b 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -436,7 +436,7 @@ impl Index { /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); /// # - /// #[derive(Serialize, Deserialize, PartialEq Debug)] + /// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// struct Movie { /// name: String, /// description: String, From 2bed778d28c120c318711eeefd6098d1751ebfb1 Mon Sep 17 00:00:00 2001 From: Isaac Cloos Date: Mon, 24 Apr 2023 09:40:52 -0400 Subject: [PATCH 7/7] `cargo fmt` cleanup --- src/client.rs | 16 +++++------ src/documents.rs | 6 ++-- src/dumps.rs | 8 +++--- src/errors.rs | 6 ++-- src/indexes.rs | 70 ++++++++++++++++++++++----------------------- src/key.rs | 8 +++--- src/search.rs | 42 +++++++++++++-------------- src/settings.rs | 74 ++++++++++++++++++++++++------------------------ src/task_info.rs | 2 +- src/tasks.rs | 4 +-- 10 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/client.rs b/src/client.rs index f01b3351..8231ba0c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -40,7 +40,7 @@ impl Client { /// # /// let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); - /// + /// /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// ``` pub fn new(host: impl Into, api_key: Option>) -> Client { @@ -665,7 +665,7 @@ impl Client { /// client.delete_key(key).await.unwrap(); /// /// let keys = client.get_keys().await.unwrap(); - /// + /// /// assert!(keys.results.iter().all(|key| key.key != inner_key)); /// # }); /// ``` @@ -698,7 +698,7 @@ impl Client { /// key.with_name(&name); /// /// let key = client.create_key(key).await.unwrap(); - /// + /// /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); @@ -733,12 +733,12 @@ impl Client { /// let new_key = KeyBuilder::new(); /// let mut new_key = client.create_key(new_key).await.unwrap(); /// let mut key_update = KeyUpdater::new(new_key); - /// + /// /// let name = "my name".to_string(); /// key_update.with_name(&name); /// /// let key = client.update_key(key_update).await.unwrap(); - /// + /// /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); @@ -784,7 +784,7 @@ impl Client { /// Wait until Meilisearch processes a [Task], and get its status. /// /// `interval` = The frequency at which the server should be polled. **Default = 50ms** - /// + /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. @@ -869,7 +869,7 @@ impl Client { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("movies_get_task", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let task = index.delete_all_documents().await.unwrap(); - /// + /// /// let task = client.get_task(task).await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -898,7 +898,7 @@ impl Client { /// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let mut query = tasks::TasksSearchQuery::new(&client); /// query.with_index_uids(["get_tasks_with"]); - /// + /// /// let tasks = client.get_tasks_with(&query).await.unwrap(); /// # }); /// ``` diff --git a/src/documents.rs b/src/documents.rs index 5aba3538..79c31856 100644 --- a/src/documents.rs +++ b/src/documents.rs @@ -131,7 +131,7 @@ impl<'a> DocumentQuery<'a> { /// id: String, /// kind: String, /// } - /// + /// /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObjectReduced { /// id: String, @@ -164,7 +164,7 @@ pub struct DocumentsQuery<'a> { pub index: &'a Index, /// The number of documents to skip. - /// + /// /// If the value of the parameter `offset` is `n`, the `n` first documents will not be returned. /// This is helpful for pagination. /// @@ -177,7 +177,7 @@ pub struct DocumentsQuery<'a> { /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// + /// /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, diff --git a/src/dumps.rs b/src/dumps.rs index 76608c6e..03274f84 100644 --- a/src/dumps.rs +++ b/src/dumps.rs @@ -1,7 +1,7 @@ //! The `dumps` module allows the creation of database dumps. -//! +//! //! - Dumps are `.dump` files that can be used to launch Meilisearch. -//! +//! //! - Dumps are compatible between Meilisearch versions. //! //! - Creating a dump is also referred to as exporting it, whereas launching Meilisearch with a dump is referred to as importing it. @@ -45,7 +45,7 @@ use crate::{client::Client, errors::Error, request::*, task_info::TaskInfo}; /// See the [dumps](crate::dumps) module. impl Client { /// Triggers a dump creation process. - /// + /// /// Once the process is complete, a dump is created in the [dumps directory](https://docs.meilisearch.com/reference/features/configuration.html#dumps-destination). /// If the dumps directory does not exist yet, it will be created. /// @@ -63,7 +63,7 @@ impl Client { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # /// let task_info = client.create_dump().await.unwrap(); - /// + /// /// assert!(matches!( /// task_info, /// TaskInfo { diff --git a/src/errors.rs b/src/errors.rs index ce6a4efb..0c6d6db3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -7,7 +7,7 @@ use thiserror::Error; #[non_exhaustive] pub enum Error { /// The exhaustive list of Meilisearch errors: - /// + /// /// Also check out: #[error(transparent)] Meilisearch(#[from] MeilisearchError), @@ -22,7 +22,7 @@ pub enum Error { #[error("A task did not succeed in time.")] Timeout, /// This Meilisearch SDK generated an invalid request (which was not sent). - /// + /// /// It probably comes from an invalid API key resulting in an invalid HTTP header. #[error("Unable to generate a valid HTTP request. It probably comes from an invalid API key.")] InvalidRequest, @@ -31,7 +31,7 @@ pub enum Error { #[error("You need to provide an api key to use the `{0}` method.")] CantUseWithoutApiKey(String), /// It is not possible to generate a tenant token with a invalid api key. - /// + /// /// Empty strings or with less than 8 characters are considered invalid. #[error("The provided api_key is invalid.")] TenantTokensInvalidApiKey, diff --git a/src/indexes.rs b/src/indexes.rs index 7618d32b..c80023f2 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -131,7 +131,7 @@ impl Index { /// # // Once the task finished, we try to create an `Index` out of it /// # .try_make_index(&client) /// # .unwrap(); - /// # + /// # /// index.primary_key = Some("special_id".to_string()); /// let task = index.update() /// .await @@ -141,7 +141,7 @@ impl Index { /// .unwrap(); /// /// let index = client.get_index("index_update").await.unwrap(); - /// + /// /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -173,7 +173,7 @@ impl Index { /// // get the index named "movies" and delete it /// let index = client.index("delete"); /// let task = index.delete().await.unwrap(); - /// + /// /// client.wait_for_task(task, None, None).await.unwrap(); /// # }); /// ``` @@ -188,7 +188,7 @@ impl Index { } /// Search for documents matching a specific query in the index. - /// + /// /// See also [Index::search]. /// /// # Example @@ -214,7 +214,7 @@ impl Index { /// /// let query = SearchQuery::new(&movies).with_query("Interstellar").with_limit(5).build(); /// let results = movies.execute_query::(&query).await.unwrap(); - /// + /// /// assert!(results.hits.len() > 0); /// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -233,7 +233,7 @@ impl Index { } /// Search for documents matching a specific query in the index. - /// + /// /// See also [Index::execute_query]. /// /// # Example @@ -273,7 +273,7 @@ impl Index { } /// Get one document using its unique id. - /// + /// /// Serde is needed. Add `serde = {version="1.0", features=["derive"]}` in the dependencies section of your Cargo.toml. /// /// # Example @@ -342,7 +342,7 @@ impl Index { /// id: String, /// kind: String, /// } - /// + /// /// #[derive(Debug, Serialize, Deserialize, PartialEq)] /// struct MyObjectReduced { /// id: String, @@ -426,16 +426,16 @@ impl Index { } /// Get documents by batch with parameters. - /// + /// /// # Example - /// + /// /// ``` /// # use serde::{Serialize, Deserialize}; /// # use meilisearch_sdk::{client::*, indexes::*, documents::*}; /// # /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); - /// # + /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] /// struct Movie { /// name: String, @@ -557,7 +557,7 @@ impl Index { } /// Add a raw and unchecked payload to meilisearch. - /// + /// /// This can be useful if your application is only forwarding data from other sources. /// /// If you send an already existing document (same id) the **whole existing document** will be overwritten by the new document. @@ -655,7 +655,7 @@ impl Index { /// name: String, /// description: String, /// } - /// + /// /// # futures::executor::block_on(async move { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("add_or_update"); @@ -712,7 +712,7 @@ impl Index { } /// Add a raw and unchecked payload to meilisearch. - /// + /// /// This can be useful if your application is only forwarding data from other sources. /// /// If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. @@ -744,7 +744,7 @@ impl Index { /// client.wait_for_task(task, None, None).await.unwrap(); /// /// let movies = movie_index.get_documents::().await.unwrap(); - /// + /// /// assert!(movies.results.len() == 2); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -801,9 +801,9 @@ impl Index { /// # /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// let movie_index = client.index("delete_all_documents"); - /// # + /// # /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// # + /// # /// movie_index.delete_all_documents() /// .await /// .unwrap() @@ -896,7 +896,7 @@ impl Index { /// # /// # // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); - /// # + /// # /// // delete some documents /// movies.delete_documents(&["Interstellar", "Unknown"]) /// .await @@ -937,7 +937,7 @@ impl Index { } /// Fetch the information of the index as a raw JSON [Index], this index should already exist. - /// + /// /// If you use it directly from the [Client], you can use the method [Client::get_raw_index], which is the equivalent method from the client. /// /// # Example @@ -953,7 +953,7 @@ impl Index { /// # let index = client.create_index("fetch_info", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let mut idx = client.index("fetch_info"); /// idx.fetch_info().await.unwrap(); - /// + /// /// println!("{idx:?}"); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -984,7 +984,7 @@ impl Index { /// .await.unwrap() /// .try_make_index(&client) /// .unwrap(); - /// + /// /// let primary_key = index.get_primary_key().await.unwrap(); /// /// assert_eq!(primary_key, Some("id")); @@ -1093,7 +1093,7 @@ impl Index { /// # let index = client.create_index("get_tasks_with", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let mut query = TasksSearchQuery::new(&client); /// query.with_index_uids(["none_existant"]); - /// + /// /// let tasks = index.get_tasks_with(&query).await.unwrap(); /// /// assert!(tasks.results.len() > 0); @@ -1124,7 +1124,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # let index = client.create_index("get_stats", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap(); /// let stats = index.get_stats().await.unwrap(); - /// + /// /// assert_eq!(stats.is_indexing, false); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -1142,7 +1142,7 @@ impl Index { /// Wait until Meilisearch processes a [Task], and get its status. /// /// `interval` = The frequency at which the server should be polled. **Default = 50ms** - /// + /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. @@ -1193,9 +1193,9 @@ impl Index { /// Add documents to the index in batches. /// /// `documents` = A slice of documents - /// + /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch - /// + /// /// **`batch_size` is 1000 by default** /// /// # Example @@ -1237,7 +1237,7 @@ impl Index { /// client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap(); /// /// let movies = movie_index.get_documents::().await.unwrap(); - /// + /// /// assert!(movies.results.len() >= 3); /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, /// # None).await.unwrap(); @@ -1259,9 +1259,9 @@ impl Index { /// Update documents to the index in batches. /// /// `documents` = A slice of documents - /// + /// /// `batch_size` = Optional parameter that allows you to specify the size of the batch - /// + /// /// **`batch_size` is 1000 by default** /// /// # Example @@ -1381,7 +1381,7 @@ impl AsRef for Index { /// .unwrap(); /// /// let index = client.get_index("index_updater").await.unwrap(); -/// +/// /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -1436,7 +1436,7 @@ impl<'a> IndexUpdater<'a> { /// .unwrap(); /// /// let index = client.get_index("index_updater_with_primary_key").await.unwrap(); - /// + /// /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -1478,7 +1478,7 @@ impl<'a> IndexUpdater<'a> { /// .unwrap(); /// /// let index = client.get_index("index_updater_execute").await.unwrap(); - /// + /// /// assert_eq!(index.primary_key, Some("special_id".to_string())); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -1553,7 +1553,7 @@ pub struct IndexesQuery<'a> { #[serde(skip_serializing)] pub client: &'a Client, /// The number of [Indexes](Index) to skip. - /// + /// /// If the value of the parameter `offset` is `n`, the `n` first indexes will not be returned. /// This is helpful for pagination. /// @@ -1562,12 +1562,12 @@ pub struct IndexesQuery<'a> { pub offset: Option, /// The maximum number of [Indexes](Index) returned. - /// + /// /// If the value of the parameter `limit` is `n`, there will never be more than `n` indexes in the response. /// This is helpful for pagination. /// /// Example: If you don't want to get more than two indexes, set limit to `2`. - /// + /// /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, diff --git a/src/key.rs b/src/key.rs index ce2d4895..de6a507f 100644 --- a/src/key.rs +++ b/src/key.rs @@ -77,7 +77,7 @@ impl Key { /// .unwrap(); /// /// key.with_name(&name); - /// + /// /// assert_eq!(key.name, Some(name)); /// # client.delete_key(key).await.unwrap(); /// # }); @@ -103,10 +103,10 @@ impl Key { /// .execute(&client) /// .await /// .unwrap(); - /// + /// /// let description = "My not so little lovely test key".to_string(); /// key.with_description(&description); - /// + /// /// let key = key.update(&client).await.unwrap(); /// /// assert_eq!(key.description, Some(description)); @@ -303,7 +303,7 @@ pub struct KeysQuery { /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// + /// /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, diff --git a/src/search.rs b/src/search.rs index 7f68e85f..4784618a 100644 --- a/src/search.rs +++ b/src/search.rs @@ -32,7 +32,7 @@ pub enum MatchingStrategies { } /// A single result. -/// +/// /// Contains the complete object, optionally the formatted object, and optionally an object that contains information about the matches. #[derive(Deserialize, Debug, Clone)] pub struct SearchResult { @@ -120,7 +120,7 @@ fn serialize_attributes_to_crop_with_wildcard( } /// Some list fields in a `SearchQuery` can be set to a wildcard value. -/// +/// /// This structure allows you to choose between the wildcard value and an exhaustive list of selectors. #[derive(Debug, Clone)] pub enum Selectors { @@ -133,9 +133,9 @@ pub enum Selectors { type AttributeToCrop<'a> = (&'a str, Option); /// A struct representing a query. -/// +/// /// You can add search parameters using the builder syntax. -/// +/// /// See [this page](https://docs.meilisearch.com/reference/features/search_parameters.html#query-q) for the official list and description of all parameters. /// /// # Examples @@ -162,7 +162,7 @@ type AttributeToCrop<'a> = (&'a str, Option); /// # .await.unwrap() /// # .try_make_index(&client) /// # .unwrap(); -/// +/// /// let mut res = SearchQuery::new(&index) /// .with_query("space") /// .with_offset(42) @@ -200,7 +200,7 @@ pub struct SearchQuery<'a> { #[serde(rename = "q")] pub query: Option<&'a str>, /// The number of documents to skip. - /// + /// /// If the value of the parameter `offset` is `n`, the `n` first documents (ordered by relevance) will not be returned. /// This is helpful for pagination. /// @@ -208,17 +208,17 @@ pub struct SearchQuery<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub offset: Option, /// The maximum number of documents returned. - /// + /// /// If the value of the parameter `limit` is `n`, there will never be more than `n` documents in the response. /// This is helpful for pagination. /// /// Example: If you don't want to get more than two documents, set limit to `2`. - /// + /// /// **Default: `20`** #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, /// The page number on which you paginate. - /// + /// /// Pagination starts at 1. If page is 0, no results are returned. /// /// **Default: None unless `hits_per_page` is defined, in which case page is `1`** @@ -230,14 +230,14 @@ pub struct SearchQuery<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub hits_per_page: Option, /// Filter applied to documents. - /// + /// /// Read the [dedicated guide](https://docs.meilisearch.com/reference/features/filtering.html) to learn the syntax. #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option>, /// Facets for which to retrieve the matching count. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. - /// + /// /// **Default: all attributes found in the documents.** #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "serialize_with_wildcard")] @@ -248,13 +248,13 @@ pub struct SearchQuery<'a> { /// Attributes to display in the returned documents. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. - /// + /// /// **Default: all attributes found in the documents.** #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "serialize_with_wildcard")] pub attributes_to_retrieve: Option>, /// Attributes whose values have to be cropped. - /// + /// /// Attributes are composed by the attribute name and an optional `usize` that overwrites the `crop_length` parameter. /// /// Can be set to a [wildcard value](enum.Selectors.html#variant.All) that will select all existing attributes. @@ -262,14 +262,14 @@ pub struct SearchQuery<'a> { #[serde(serialize_with = "serialize_attributes_to_crop_with_wildcard")] pub attributes_to_crop: Option]>>, /// Maximum number of words including the matched query term(s) contained in the returned cropped value(s). - /// + /// /// See [attributes_to_crop](#structfield.attributes_to_crop). /// /// **Default: `10`** #[serde(skip_serializing_if = "Option::is_none")] pub crop_length: Option, /// Marker at the start and the end of a cropped value. - /// + /// /// ex: `...middle of a crop...` /// /// **Default: `...`** @@ -282,14 +282,14 @@ pub struct SearchQuery<'a> { #[serde(serialize_with = "serialize_with_wildcard")] pub attributes_to_highlight: Option>, /// Tag in front of a highlighted term. - /// + /// /// ex: `hello world` /// /// **Default: ``** #[serde(skip_serializing_if = "Option::is_none")] pub highlight_pre_tag: Option<&'a str>, /// Tag after the a highlighted term. - /// + /// /// ex: `hello world` /// /// **Default: ``** @@ -348,7 +348,7 @@ impl<'a> SearchQuery<'a> { self } /// Add the page number on which to paginate. - /// + /// /// # Example /// /// ``` @@ -367,7 +367,7 @@ impl<'a> SearchQuery<'a> { /// # } /// # client.create_index("search_with_page", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("search_with_page"); - /// + /// /// let mut query = SearchQuery::new(&index); /// query.with_query("").with_page(2); /// let res = query.execute::().await.unwrap(); @@ -380,7 +380,7 @@ impl<'a> SearchQuery<'a> { } /// Add the maximum number of results per page. - /// + /// /// # Example /// /// ``` @@ -399,7 +399,7 @@ impl<'a> SearchQuery<'a> { /// # } /// # client.create_index("search_with_hits_per_page", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("search_with_hits_per_page"); - /// + /// /// let mut query = SearchQuery::new(&index); /// query.with_query("").with_hits_per_page(2); /// let res = query.execute::().await.unwrap(); diff --git a/src/settings.rs b/src/settings.rs index 92c3c204..8ba35cfa 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -20,7 +20,7 @@ pub struct FacetingSettings { } /// Struct reprensenting a set of settings. -/// +/// /// You can build this struct using the builder syntax. /// /// # Example @@ -234,7 +234,7 @@ impl Index { /// Get [Settings] of the [Index]. /// /// # Example - /// + /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; /// # @@ -245,7 +245,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_settings", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_settings"); - /// + /// /// let settings = index.get_settings().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -261,9 +261,9 @@ impl Index { } /// Get [synonyms](https://docs.meilisearch.com/reference/features/synonyms.html) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -275,7 +275,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_synonyms", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_synonyms"); - /// + /// /// let synonyms = index.get_synonyms().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -294,9 +294,9 @@ impl Index { } /// Get [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -308,7 +308,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_pagination"); - /// + /// /// let pagination = index.get_pagination().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -329,7 +329,7 @@ impl Index { /// Get [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index]. /// /// # Example - /// + /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; /// # @@ -340,7 +340,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_stop_words", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_stop_words"); - /// + /// /// let stop_words = index.get_stop_words().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -359,9 +359,9 @@ impl Index { } /// Get [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#ranking-rules) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -373,7 +373,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_ranking_rules", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_ranking_rules"); - /// + /// /// let ranking_rules = index.get_ranking_rules().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -392,9 +392,9 @@ impl Index { } /// Get [filterable attributes](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -406,7 +406,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_filterable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_filterable_attributes"); - /// + /// /// let filterable_attributes = index.get_filterable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -425,9 +425,9 @@ impl Index { } /// Get [sortable attributes](https://docs.meilisearch.com/reference/features/sorting.html) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -439,7 +439,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_sortable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_sortable_attributes"); - /// + /// /// let sortable_attributes = index.get_sortable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -458,9 +458,9 @@ impl Index { } /// Get the [distinct attribute](https://docs.meilisearch.com/reference/features/settings.html#distinct-attribute) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -472,7 +472,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_distinct_attribute", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_distinct_attribute"); - /// + /// /// let distinct_attribute = index.get_distinct_attribute().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -491,9 +491,9 @@ impl Index { } /// Get [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -505,7 +505,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_searchable_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_searchable_attributes"); - /// + /// /// let searchable_attributes = index.get_searchable_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -524,9 +524,9 @@ impl Index { } /// Get [displayed attributes](https://docs.meilisearch.com/reference/features/settings.html#displayed-attributes) of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -538,7 +538,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_displayed_attributes", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_displayed_attributes"); - /// + /// /// let displayed_attributes = index.get_displayed_attributes().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -557,9 +557,9 @@ impl Index { } /// Get [faceting](https://docs.meilisearch.com/reference/api/settings.html#faceting) settings of the [Index]. - /// + /// /// # Example - /// + /// /// /// ``` /// # use meilisearch_sdk::{client::*, indexes::*}; @@ -571,7 +571,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("get_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let index = client.index("get_faceting"); - /// + /// /// let faceting = index.get_faceting().await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # }); @@ -590,7 +590,7 @@ impl Index { } /// Update [settings](../settings/struct.Settings.html) of the [Index]. - /// + /// /// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged. /// /// # Example @@ -686,7 +686,7 @@ impl Index { /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); /// # client.create_index("set_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// let mut index = client.index("set_pagination"); - /// + /// /// let pagination = PaginationSetting {max_total_hits:100}; /// let task = index.set_pagination(pagination).await.unwrap(); /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); @@ -1045,7 +1045,7 @@ impl Index { } /// Reset [Settings] of the [Index]. - /// + /// /// All settings will be reset to their [default value](https://docs.meilisearch.com/reference/api/settings.html#reset-settings). /// /// # Example @@ -1171,7 +1171,7 @@ impl Index { } /// Reset [ranking rules](https://docs.meilisearch.com/learn/core_concepts/relevancy.html#ranking-rules) of the [Index] to default value. - /// + /// /// **Default value: `["words", "typo", "proximity", "attribute", "sort", "exactness"]`.** /// /// # Example @@ -1300,7 +1300,7 @@ impl Index { .await } - /// Reset [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of + /// Reset [searchable attributes](https://docs.meilisearch.com/reference/features/field_properties.html#searchable-fields) of /// the [Index] (enable all attributes). /// /// # Example diff --git a/src/task_info.rs b/src/task_info.rs index 2f796fcf..28f79f34 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -30,7 +30,7 @@ impl TaskInfo { /// Wait until Meilisearch processes a task provided by [TaskInfo], and get its status. /// /// `interval` = The frequency at which the server should be polled. **Default = 50ms** - /// + /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. diff --git a/src/tasks.rs b/src/tasks.rs index 405888b1..1e1f49ca 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -216,7 +216,7 @@ impl Task { /// Wait until Meilisearch processes a [Task], and get its status. /// /// `interval` = The frequency at which the server should be polled. **Default = 50ms** - /// + /// /// `timeout` = The maximum time to wait for processing to complete. **Default = 5000ms** /// /// If the waited time exceeds `timeout` then an [Error::Timeout] will be returned. @@ -421,7 +421,7 @@ impl Task { /// .await /// .unwrap(); /// let task = client.get_task(task_info).await.unwrap(); - /// + /// /// assert!(task.is_pending()); /// # task.wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap().delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); /// # });