Skip to content

Commit 026fbbc

Browse files
committed
Add facet search setting methods
1 parent 24d4d7f commit 026fbbc

File tree

1 file changed

+148
-1
lines changed

1 file changed

+148
-1
lines changed

src/settings.rs

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,40 @@ impl<Http: HttpClient> Index<Http> {
795795
.await
796796
}
797797

798-
/// Get [typo tolerance](https://www.meilisearch.com/docs/reference/api/settings#typo-tolerance) of the [Index].
798+
/// Get [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) of the [Index].
799+
///
800+
/// # Example
801+
///
802+
/// ```
803+
/// # use meilisearch_sdk::{client::*, indexes::*};
804+
/// #
805+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
806+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
807+
/// #
808+
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
809+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
810+
/// # client.create_index("get_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
811+
/// let index = client.index("get_facet_search");
812+
///
813+
/// let facet_search = index.get_facet_search().await.unwrap();
814+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
815+
/// # });
816+
/// ```
817+
pub async fn get_facet_search(&self) -> Result<bool, Error> {
818+
self.client
819+
.http_client
820+
.request::<(), (), bool>(
821+
&format!(
822+
"{}/indexes/{}/settings/facet-search",
823+
self.client.host, self.uid
824+
),
825+
Method::Get { query: () },
826+
200,
827+
)
828+
.await
829+
}
830+
831+
/// Get [typo tolerance](https://www.meilisearch.com/docs/learn/configuration/typo_tolerance#typo-tolerance) of the [Index].
799832
///
800833
/// ```
801834
/// # use meilisearch_sdk::{client::*, indexes::*};
@@ -1629,6 +1662,45 @@ impl<Http: HttpClient> Index<Http> {
16291662
.await
16301663
}
16311664

1665+
/// update [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) settings of the [Index].
1666+
///
1667+
/// # Example
1668+
///
1669+
/// ```
1670+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1671+
/// #
1672+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1673+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1674+
/// #
1675+
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
1676+
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
1677+
/// # client.create_index("set_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1678+
/// let mut index = client.index("set_facet_search");
1679+
///
1680+
/// let task = index.set_facet_search(false).await.unwrap();
1681+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1682+
/// # });
1683+
/// ```
1684+
pub async fn set_facet_search(
1685+
&self,
1686+
facet_search: bool,
1687+
) -> Result<TaskInfo, Error> {
1688+
self.client
1689+
.http_client
1690+
.request::<(), bool, TaskInfo>(
1691+
&format!(
1692+
"{}/indexes/{}/settings/facet-search",
1693+
self.client.host, self.uid
1694+
),
1695+
Method::Put {
1696+
query: (),
1697+
body: facet_search,
1698+
},
1699+
202,
1700+
)
1701+
.await
1702+
}
1703+
16321704
/// Update [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index].
16331705
///
16341706
/// # Example
@@ -2172,6 +2244,39 @@ impl<Http: HttpClient> Index<Http> {
21722244
.await
21732245
}
21742246

2247+
/// Reset [facet-search settings](https://www.meilisearch.com/docs/reference/api/settings#facet-search) settings of the [Index].
2248+
///
2249+
/// # Example
2250+
///
2251+
/// ```
2252+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
2253+
/// #
2254+
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
2255+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
2256+
/// #
2257+
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
2258+
/// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
2259+
/// # client.create_index("reset_facet_search", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2260+
/// let mut index = client.index("reset_facet_search");
2261+
///
2262+
/// let task = index.reset_facet_search().await.unwrap();
2263+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2264+
/// # });
2265+
/// ```
2266+
pub async fn reset_facet_search(&self) -> Result<TaskInfo, Error> {
2267+
self.client
2268+
.http_client
2269+
.request::<(), (), TaskInfo>(
2270+
&format!(
2271+
"{}/indexes/{}/settings/facet-search",
2272+
self.client.host, self.uid
2273+
),
2274+
Method::Delete { query: () },
2275+
202,
2276+
)
2277+
.await
2278+
}
2279+
21752280
/// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index].
21762281
///
21772282
/// # Example
@@ -2558,6 +2663,48 @@ mod tests {
25582663
assert_eq!(expected, default);
25592664
}
25602665

2666+
#[meilisearch_test]
2667+
async fn test_get_facet_search(index: Index) {
2668+
let expected = true;
2669+
2670+
let res = index.get_facet_search().await.unwrap();
2671+
2672+
assert_eq!(expected, res);
2673+
}
2674+
2675+
#[meilisearch_test]
2676+
async fn test_set_facet_search(client: Client, index: Index) {
2677+
let expected = false;
2678+
2679+
let task_info = index
2680+
.set_facet_search(false)
2681+
.await
2682+
.unwrap();
2683+
client.wait_for_task(task_info, None, None).await.unwrap();
2684+
2685+
let res = index.get_facet_search().await.unwrap();
2686+
2687+
assert_eq!(expected, res);
2688+
}
2689+
2690+
#[meilisearch_test]
2691+
async fn test_reset_facet_search(index: Index) {
2692+
let expected = true;
2693+
2694+
let task = index
2695+
.set_facet_search(false)
2696+
.await
2697+
.unwrap();
2698+
index.wait_for_task(task, None, None).await.unwrap();
2699+
2700+
let reset_task = index.reset_facet_search().await.unwrap();
2701+
index.wait_for_task(reset_task, None, None).await.unwrap();
2702+
2703+
let default = index.get_facet_search().await.unwrap();
2704+
2705+
assert_eq!(expected, default);
2706+
}
2707+
25612708
#[meilisearch_test]
25622709
async fn test_get_search_cutoff_ms(index: Index) {
25632710
let expected = None;

0 commit comments

Comments
 (0)