Skip to content
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

Support facet search and prefix search settings #634

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,42 @@ reset_proximity_precision_settings_1: |-
.reset_proximity_precision()
.await
.unwrap();
get_facet_search_settings_1: |-
let facet_search: bool = client
.index(INDEX_UID)
.get_facet_search()
.await
.unwrap();
update_facet_search_settings_1: |-
let task: TaskInfo = client
.index(INDEX_UID)
.set_facet_search(false)
.await
.unwrap();
reset_facet_search_settings_1: |-
let task: TaskInfo = client
.index(INDEX_UID)
.reset_facet_search()
.await
.unwrap();
get_prefix_search_settings_1: |-
let prefix_search: String = client
.index(INDEX_UID)
.get_prefix_search()
.await
.unwrap();
update_prefix_search_settings_1: |-
let task: TaskInfo = client
.index(INDEX_UID)
.set_prefix_search("disabled".to_string())
.await
.unwrap();
reset_prefix_search_settings_1: |-
let task: TaskInfo = client
.index(INDEX_UID)
.reset_prefix_search()
.await
.unwrap();
get_search_cutoff_1: |-
let search_cutoff_ms: String = client
.index("movies")
Expand Down
282 changes: 282 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,72 @@ impl<Http: HttpClient> Index<Http> {
.await
}

/// Get [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) of the [Index].
///
/// # 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");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("get_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let index = client.index("get_facet_search");
///
/// let facet_search = index.get_facet_search().await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn get_facet_search(&self) -> Result<bool, Error> {
self.client
.http_client
.request::<(), (), bool>(
&format!(
"{}/indexes/{}/settings/facet-search",
self.client.host, self.uid
),
Method::Get { query: () },
200,
)
.await
}

/// Get [prefix-search settings](https://www.meilisearch.com/docs/reference/api/settings#prefix-search) of the [Index].
///
/// # 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");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("get_prefix_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let index = client.index("get_prefix_search");
///
/// let prefix_search = index.get_prefix_search().await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn get_prefix_search(&self) -> Result<String, Error> {
self.client
.http_client
.request::<(), (), String>(
&format!(
"{}/indexes/{}/settings/prefix-search",
self.client.host, self.uid
),
Method::Get { query: () },
200,
)
.await
}

/// Get [typo tolerance](https://www.meilisearch.com/docs/learn/configuration/typo_tolerance#typo-tolerance) of the [Index].
///
/// ```
Expand Down Expand Up @@ -1629,6 +1695,78 @@ impl<Http: HttpClient> Index<Http> {
.await
}

/// update [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) settings of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("set_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let mut index = client.index("set_facet_search");
///
/// let task = index.set_facet_search(false).await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn set_facet_search(&self, facet_search: bool) -> Result<TaskInfo, Error> {
self.client
.http_client
.request::<(), bool, TaskInfo>(
&format!(
"{}/indexes/{}/settings/facet-search",
self.client.host, self.uid
),
Method::Put {
query: (),
body: facet_search,
},
202,
)
.await
}

/// update [prefix-search settings](https://www.meilisearch.com/docs/reference/api/settings#prefix-search) settings of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("set_prefix_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let mut index = client.index("set_prefix_search");
///
/// let task = index.set_prefix_search("disabled".to_string()).await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn set_prefix_search(&self, prefix_search: String) -> Result<TaskInfo, Error> {
self.client
.http_client
.request::<(), String, TaskInfo>(
&format!(
"{}/indexes/{}/settings/prefix-search",
self.client.host, self.uid
),
Method::Put {
query: (),
body: prefix_search,
},
202,
)
.await
}

/// Update [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index].
///
/// # Example
Expand Down Expand Up @@ -2172,6 +2310,72 @@ impl<Http: HttpClient> Index<Http> {
.await
}

/// Reset [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) settings of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("reset_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let mut index = client.index("reset_facet_search");
///
/// let task = index.reset_facet_search().await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn reset_facet_search(&self) -> Result<TaskInfo, Error> {
self.client
.http_client
.request::<(), (), TaskInfo>(
&format!(
"{}/indexes/{}/settings/facet-search",
self.client.host, self.uid
),
Method::Delete { query: () },
202,
)
.await
}

/// Reset [prefix-search settings](https://www.meilisearch.com/docs/reference/api/settings#prefix-search) settings of the [Index].
///
/// # Example
///
/// ```
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
/// #
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
/// #
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
/// # client.create_index("reset_prefix_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// let mut index = client.index("reset_prefix_search");
///
/// let task = index.reset_prefix_search().await.unwrap();
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
/// # });
/// ```
pub async fn reset_prefix_search(&self) -> Result<TaskInfo, Error> {
self.client
.http_client
.request::<(), (), TaskInfo>(
&format!(
"{}/indexes/{}/settings/prefix-search",
self.client.host, self.uid
),
Method::Delete { query: () },
202,
)
.await
}

/// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index].
///
/// # Example
Expand Down Expand Up @@ -2558,6 +2762,84 @@ mod tests {
assert_eq!(expected, default);
}

#[meilisearch_test]
async fn test_get_facet_search(index: Index) {
let expected = true;

let res = index.get_facet_search().await.unwrap();

assert_eq!(expected, res);
}

#[meilisearch_test]
async fn test_set_facet_search(client: Client, index: Index) {
let expected = false;

let task_info = index.set_facet_search(false).await.unwrap();
client.wait_for_task(task_info, None, None).await.unwrap();

let res = index.get_facet_search().await.unwrap();

assert_eq!(expected, res);
}

#[meilisearch_test]
async fn test_reset_facet_search(index: Index) {
let expected = true;

let task = index.set_facet_search(false).await.unwrap();
index.wait_for_task(task, None, None).await.unwrap();

let reset_task = index.reset_facet_search().await.unwrap();
index.wait_for_task(reset_task, None, None).await.unwrap();

let default = index.get_facet_search().await.unwrap();

assert_eq!(expected, default);
}

#[meilisearch_test]
async fn test_get_prefix_search(index: Index) {
let expected = "indexingTime".to_string();

let res = index.get_prefix_search().await.unwrap();

assert_eq!(expected, res);
}

#[meilisearch_test]
async fn test_set_prefix_search(client: Client, index: Index) {
let expected = "disabled".to_string();

let task_info = index
.set_prefix_search("disabled".to_string())
.await
.unwrap();
client.wait_for_task(task_info, None, None).await.unwrap();

let res = index.get_prefix_search().await.unwrap();

assert_eq!(expected, res);
}

#[meilisearch_test]
async fn test_reset_prefix_search(index: Index) {
let expected = "indexingTime".to_string();

let task = index
.set_prefix_search("disabled".to_string())
.await
.unwrap();
index.wait_for_task(task, None, None).await.unwrap();

let reset_task = index.reset_prefix_search().await.unwrap();
index.wait_for_task(reset_task, None, None).await.unwrap();

let default = index.get_prefix_search().await.unwrap();

assert_eq!(expected, default);
}

#[meilisearch_test]
async fn test_get_search_cutoff_ms(index: Index) {
let expected = None;
Expand Down
Loading