Skip to content

Add support to the pagination setting customization at the index level #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,27 @@ reset_synonyms_1: |-
.reset_synonyms()
.await
.unwrap();
get_pagination_settings_1: |-
let pagination: HashMap<String, i32> = client
.index("movies")
.get_pagination()
.await
.unwrap();
update_pagination_settings_1: |-
let mut pagination = std::collections::HashMap::new();
pagination.insert(String::from("maxTotalHits"), 100);

let task: TaskInfo = client
.index("movies")
.set_pagination(&pagination)
.await
.unwrap();
reset_pagination_settings_1: |-
let task: TaskInfo = client
.index("movies")
.reset_pagination()
.await
.unwrap();
get_stop_words_1: |-
let stop_words: Vec<String> = client
.index("movies")
Expand Down Expand Up @@ -635,6 +656,15 @@ settings_guide_searchable_1: |-
.set_settings(&settings)
.await
.unwrap();
settings_guide_pagination_1: |-
let mut pagination = std::collections::HashMap::new();
pagination.insert(String::from("maxTotalHits"), 100);

let task: TaskInfo = client
.index("books")
.set_pagination(&pagination)
.await
.unwrap();
settings_guide_displayed_1: |-
let settings = Settings::new()
.with_displayed_attributes([
Expand Down
96 changes: 96 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,35 @@ impl Index {
.await
}

/// Get [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*};
/// #
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").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_HOST, 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();
/// # });
/// ```
pub async fn get_pagination(&self) -> Result<HashMap<String, i32>, Error> {
request::<(), HashMap<String, i32>>(
&format!(
"{}/indexes/{}/settings/pagination",
self.client.host, self.uid
),
&self.client.api_key,
Method::Get(()),
200,
)
.await
}

/// Get [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
///
/// ```
Expand Down Expand Up @@ -528,6 +557,42 @@ impl Index {
.await
}

/// Update [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").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_HOST, 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 mut pagination = std::collections::HashMap::new();
/// pagination.insert(String::from("maxTotalHits"), 100);
/// let task = index.set_pagination(&pagination).await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn set_pagination(
&self,
pagination: &HashMap<String, i32>,
) -> Result<TaskInfo, Error> {
request::<&HashMap<String, i32>, TaskInfo>(
&format!(
"{}/indexes/{}/settings/pagination",
self.client.host, self.uid
),
&self.client.api_key,
Method::Patch(pagination),
202,
)
.await
}

/// Update [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
///
/// # Example
Expand Down Expand Up @@ -878,6 +943,37 @@ impl Index {
.await
}

/// Reset [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").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_HOST, 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");
///
/// let task = index.reset_pagination().await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn reset_pagination(&self) -> Result<TaskInfo, Error> {
request::<(), TaskInfo>(
&format!(
"{}/indexes/{}/settings/pagination",
self.client.host, self.uid
),
&self.client.api_key,
Method::Delete,
202,
)
.await
}
/// Reset [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
///
/// # Example
Expand Down