Skip to content

Commit 0674a1e

Browse files
committed
handle defaults
1 parent 47c80a9 commit 0674a1e

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

src/settings.rs

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ pub struct PaginationSetting {
1313
pub max_total_hits: usize,
1414
}
1515

16-
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
16+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
1717
#[serde(rename_all = "camelCase")]
1818
pub struct MinWordSizeForTypos {
19-
pub one_typo: i64,
20-
pub two_typos: i64,
19+
pub one_typo: Option<i64>,
20+
pub two_typos: Option<i64>,
2121
}
2222

23-
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
23+
impl Default for MinWordSizeForTypos {
24+
fn default() -> Self {
25+
MinWordSizeForTypos {
26+
one_typo: Some(5),
27+
two_typos: Some(9),
28+
}
29+
}
30+
}
31+
32+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
2433
#[serde(rename_all = "camelCase")]
2534
pub struct TypoToleranceSettings {
2635
pub enabled: Option<bool>,
@@ -29,6 +38,17 @@ pub struct TypoToleranceSettings {
2938
pub min_word_size_for_typos: Option<MinWordSizeForTypos>,
3039
}
3140

41+
impl Default for TypoToleranceSettings {
42+
fn default() -> Self {
43+
TypoToleranceSettings {
44+
enabled: Some(true),
45+
disable_on_attributes: Some(vec![]),
46+
disable_on_words: Some(vec![]),
47+
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
48+
}
49+
}
50+
}
51+
3252
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]
3353
#[serde(rename_all = "camelCase")]
3454
pub struct FacetingSettings {
@@ -1050,14 +1070,7 @@ impl Index {
10501070
/// # client.create_index("set_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
10511071
/// let mut index = client.index("set_typo_tolerance");
10521072
///
1053-
/// let mut typo_tolerance = TypoToleranceSettings {
1054-
/// enabled: Some(true),
1055-
/// disable_on_attributes: None,
1056-
/// disable_on_words: None,
1057-
/// min_word_size_for_typos: Some(MinWordSizeForTypos {
1058-
/// one_typo: 5,
1059-
/// two_typos: 9})
1060-
/// };
1073+
/// let mut typo_tolerance = TypoToleranceSettings::default();
10611074
///
10621075
/// let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
10631076
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
@@ -1563,15 +1576,7 @@ mod tests {
15631576

15641577
#[meilisearch_test]
15651578
async fn test_get_typo_tolerance(index: Index) {
1566-
let typo_tolerance = TypoToleranceSettings {
1567-
enabled: Some(true),
1568-
disable_on_attributes: None,
1569-
disable_on_words: None,
1570-
min_word_size_for_typos: Some(MinWordSizeForTypos {
1571-
one_typo: 5,
1572-
two_typos: 9,
1573-
}),
1574-
};
1579+
let typo_tolerance = TypoToleranceSettings::default();
15751580

15761581
let res = index.get_typo_tolerance().await.unwrap();
15771582

@@ -1582,11 +1587,11 @@ mod tests {
15821587
async fn test_set_typo_tolerance(client: Client, index: Index) {
15831588
let typo_tolerance = TypoToleranceSettings {
15841589
enabled: Some(false),
1585-
disable_on_attributes: None,
1586-
disable_on_words: None,
1590+
disable_on_attributes: Some(vec![]),
1591+
disable_on_words: Some(vec![]),
15871592
min_word_size_for_typos: Some(MinWordSizeForTypos {
1588-
one_typo: 6,
1589-
two_typos: 9,
1593+
one_typo: Some(6),
1594+
two_typos: Some(9),
15901595
}),
15911596
};
15921597
let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
@@ -1601,20 +1606,11 @@ mod tests {
16011606
async fn test_reset_typo_tolerance(index: Index) {
16021607
let typo_tolerance = TypoToleranceSettings {
16031608
enabled: Some(false),
1604-
disable_on_attributes: None,
1605-
disable_on_words: None,
1609+
disable_on_attributes: Some(vec![]),
1610+
disable_on_words: Some(vec![]),
16061611
min_word_size_for_typos: Some(MinWordSizeForTypos {
1607-
one_typo: 1,
1608-
two_typos: 2,
1609-
}),
1610-
};
1611-
let default = TypoToleranceSettings {
1612-
enabled: Some(true),
1613-
disable_on_attributes: None,
1614-
disable_on_words: None,
1615-
min_word_size_for_typos: Some(MinWordSizeForTypos {
1616-
one_typo: 5,
1617-
two_typos: 9,
1612+
one_typo: Some(1),
1613+
two_typos: Some(2),
16181614
}),
16191615
};
16201616

@@ -1626,6 +1622,6 @@ mod tests {
16261622

16271623
let res = index.get_typo_tolerance().await.unwrap();
16281624

1629-
assert_eq!(default, res);
1625+
assert_eq!(TypoToleranceSettings::default(), res);
16301626
}
16311627
}

0 commit comments

Comments
 (0)