Skip to content

Commit da08977

Browse files
committed
resolve conflicts
1 parent b3a882b commit da08977

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

src/settings.rs

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ pub struct PaginationSetting {
1313
pub max_total_hits: usize,
1414
}
1515

16+
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
17+
#[serde(rename_all = "camelCase")]
18+
pub struct MinWordSizeForTypos {
19+
pub one_typo: i64,
20+
pub two_typos: i64,
21+
}
22+
23+
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
24+
#[serde(rename_all = "camelCase")]
25+
pub struct TypoToleranceSettings {
26+
pub enabled: bool,
27+
pub disable_on_attributes: Vec<String>,
28+
pub disable_on_words: Vec<String>,
29+
pub min_word_size_for_typos: MinWordSizeForTypos,
30+
}
31+
1632
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]
1733
#[serde(rename_all = "camelCase")]
1834
pub struct FacetingSettings {
@@ -77,6 +93,9 @@ pub struct Settings {
7793
/// Faceting settings
7894
#[serde(skip_serializing_if = "Option::is_none")]
7995
pub faceting: Option<FacetingSettings>,
96+
/// TypoTolerance settings
97+
#[serde(skip_serializing_if = "Option::is_none")]
98+
pub typo_tolerance: Option<TypoToleranceSettings>,
8099
}
81100

82101
#[allow(missing_docs)]
@@ -94,6 +113,7 @@ impl Settings {
94113
displayed_attributes: None,
95114
pagination: None,
96115
faceting: None,
116+
typo_tolerance: None,
97117
}
98118
}
99119
pub fn with_synonyms<S, U, V>(self, synonyms: HashMap<S, U>) -> Settings
@@ -140,6 +160,13 @@ impl Settings {
140160
}
141161
}
142162

163+
pub fn with_typo_tolerance(self, typo_tolerance_settings: TypoToleranceSettings) -> Settings {
164+
Settings {
165+
typo_tolerance: Some(typo_tolerance_settings),
166+
..self
167+
}
168+
}
169+
143170
pub fn with_ranking_rules(
144171
self,
145172
ranking_rules: impl IntoIterator<Item = impl AsRef<str>>,
@@ -547,6 +574,35 @@ impl Index {
547574
.await
548575
}
549576

577+
/// Get [typo tolerance](https://docs.meilisearch.com/learn/configuration/typo_tolerance.html#typo-tolerance) of the [Index].
578+
///
579+
/// ```
580+
/// # use meilisearch_sdk::{client::*, indexes::*};
581+
/// #
582+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
583+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
584+
/// #
585+
/// # futures::executor::block_on(async move {
586+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
587+
/// # client.create_index("get_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
588+
/// let index = client.index("get_typo_tolerance");
589+
/// let typotolerance = index.get_typo_tolerance().await.unwrap();
590+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
591+
/// # });
592+
/// ```
593+
pub async fn get_typo_tolerance(&self) -> Result<TypoToleranceSettings, Error> {
594+
request::<(), TypoToleranceSettings>(
595+
&format!(
596+
"{}/indexes/{}/settings/typo-tolerance",
597+
self.client.host, self.uid
598+
),
599+
&self.client.api_key,
600+
Method::Get(()),
601+
200,
602+
)
603+
.await
604+
}
605+
550606
/// Update [settings](../settings/struct.Settings.html) of the [Index].
551607
/// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged.
552608
///
@@ -979,6 +1035,48 @@ impl Index {
9791035
.await
9801036
}
9811037

1038+
/// Update [typo tolerance](https://docs.meilisearch.com/learn/configuration/typo_tolerance.html#typo-tolerance) settings of the [Index].
1039+
///
1040+
/// # Example
1041+
///
1042+
/// ```
1043+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::{TypoToleranceSettings, MinWordSizeForTypos}};
1044+
/// #
1045+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
1046+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1047+
/// #
1048+
/// # futures::executor::block_on(async move {
1049+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1050+
/// # client.create_index("set_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1051+
/// let mut index = client.index("set_typo_tolerance");
1052+
///
1053+
/// let mut typo_tolerance = TypoToleranceSettings {
1054+
/// enabled: true,
1055+
/// disable_on_attributes: vec!(),
1056+
/// disable_on_words: vec!(),
1057+
/// min_word_size_for_typos: MinWordSizeForTypos { one_typo : 1, two_typos: 2},
1058+
/// };
1059+
///
1060+
/// let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
1061+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1062+
/// # });
1063+
/// ```
1064+
pub async fn set_typo_tolerance(
1065+
&self,
1066+
typo_tolerance: &TypoToleranceSettings,
1067+
) -> Result<TaskInfo, Error> {
1068+
request::<&TypoToleranceSettings, TaskInfo>(
1069+
&format!(
1070+
"{}/indexes/{}/settings/typo-tolerance",
1071+
self.client.host, self.uid
1072+
),
1073+
&self.client.api_key,
1074+
Method::Patch(typo_tolerance),
1075+
202,
1076+
)
1077+
.await
1078+
}
1079+
9821080
/// Reset [Settings] of the [Index].
9831081
/// All settings will be reset to their [default value](https://docs.meilisearch.com/reference/api/settings.html#reset-settings).
9841082
///
@@ -1328,6 +1426,38 @@ impl Index {
13281426
)
13291427
.await
13301428
}
1429+
1430+
/// Reset [typo tolerance](https://docs.meilisearch.com/learn/configuration/typo_tolerance.html#typo-tolerance) settings of the [Index].
1431+
///
1432+
/// # Example
1433+
///
1434+
/// ```
1435+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1436+
/// #
1437+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
1438+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1439+
/// #
1440+
/// # futures::executor::block_on(async move {
1441+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1442+
/// # client.create_index("reset_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1443+
/// let mut index = client.index("reset_typo_tolerance");
1444+
///
1445+
/// let task = index.reset_typo_tolerance().await.unwrap();
1446+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1447+
/// # });
1448+
/// ```
1449+
pub async fn reset_typo_tolerance(&self) -> Result<TaskInfo, Error> {
1450+
request::<(), TaskInfo>(
1451+
&format!(
1452+
"{}/indexes/{}/settings/typo-tolerance",
1453+
self.client.host, self.uid
1454+
),
1455+
&self.client.api_key,
1456+
Method::Delete,
1457+
202,
1458+
)
1459+
.await
1460+
}
13311461
}
13321462

13331463
#[cfg(test)]
@@ -1428,4 +1558,72 @@ mod tests {
14281558

14291559
assert_eq!(default, res);
14301560
}
1561+
1562+
#[meilisearch_test]
1563+
async fn test_get_typo_tolerance(index: Index) {
1564+
let typo_tolerance = TypoToleranceSettings {
1565+
enabled: true,
1566+
disable_on_attributes: vec![],
1567+
disable_on_words: vec![],
1568+
min_word_size_for_typos: MinWordSizeForTypos {
1569+
one_typo: 5,
1570+
two_typos: 9,
1571+
},
1572+
};
1573+
1574+
let res = index.get_typo_tolerance().await.unwrap();
1575+
1576+
assert_eq!(typo_tolerance, res);
1577+
}
1578+
1579+
#[meilisearch_test]
1580+
async fn test_set_typo_tolerance(client: Client, index: Index) {
1581+
let typo_tolerance = TypoToleranceSettings {
1582+
enabled: false,
1583+
disable_on_attributes: vec![],
1584+
disable_on_words: vec![],
1585+
min_word_size_for_typos: MinWordSizeForTypos {
1586+
one_typo: 6,
1587+
two_typos: 9,
1588+
},
1589+
};
1590+
let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
1591+
client.wait_for_task(task_info, None, None).await.unwrap();
1592+
1593+
let res = index.get_typo_tolerance().await.unwrap();
1594+
1595+
assert_eq!(typo_tolerance, res);
1596+
}
1597+
1598+
#[meilisearch_test]
1599+
async fn test_reset_typo_tolerance(index: Index) {
1600+
let typo_tolerance = TypoToleranceSettings {
1601+
enabled: false,
1602+
disable_on_attributes: vec![],
1603+
disable_on_words: vec![],
1604+
min_word_size_for_typos: MinWordSizeForTypos {
1605+
one_typo: 1,
1606+
two_typos: 2,
1607+
},
1608+
};
1609+
let default = TypoToleranceSettings {
1610+
enabled: true,
1611+
disable_on_attributes: vec![],
1612+
disable_on_words: vec![],
1613+
min_word_size_for_typos: MinWordSizeForTypos {
1614+
one_typo: 5,
1615+
two_typos: 9,
1616+
},
1617+
};
1618+
1619+
let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
1620+
index.wait_for_task(task, None, None).await.unwrap();
1621+
1622+
let reset_task = index.reset_typo_tolerance().await.unwrap();
1623+
index.wait_for_task(reset_task, None, None).await.unwrap();
1624+
1625+
let res = index.get_typo_tolerance().await.unwrap();
1626+
1627+
assert_eq!(default, res);
1628+
}
14311629
}

0 commit comments

Comments
 (0)