Skip to content

Commit 9c56ee1

Browse files
committed
Set default val of Typo Tolerance properties to None
1 parent 07ec09f commit 9c56ee1

File tree

2 files changed

+51
-52
lines changed

2 files changed

+51
-52
lines changed

.code-samples.meilisearch.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ getting_started_typo_tolerance: |-
400400
}
401401
let typo_tolerance = TypoToleranceSettings {
402402
enabled: Some(true),
403+
disable_on_attributes: Some(vec![]),
403404
disable_on_words: Some(vec!["title".to_string()]),
404405
min_word_size_for_typos: Some(min_word_size_for_typos),
405406
};
@@ -418,9 +419,9 @@ get_typo_tolerance_1: |-
418419
update_typo_tolerance_1: |-
419420
let typo_tolerance = TypoToleranceSettings {
420421
enabled: Some(false),
421-
disable_on_attributes: Some(vec![]),
422-
disable_on_words: Some(vec![]),
423-
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
422+
disable_on_attributes: None,
423+
disable_on_words: None,
424+
min_word_size_for_typos: None,
424425
};
425426
426427
let task: TaskInfo = client
@@ -843,6 +844,7 @@ settings_guide_typo_tolerance_1: |-
843844
}
844845
let typo_tolerance = TypoToleranceSettings {
845846
enabled: Some(true),
847+
disable_on_attributes: None,
846848
disable_on_words: Some(vec!["title".to_string()]),
847849
min_word_size_for_typos: Some(min_word_size_for_typos),
848850
};
@@ -858,7 +860,9 @@ settings_guide_typo_tolerance_1: |-
858860
typo_tolerance_guide_1: |-
859861
let typo_tolerance = TypoToleranceSettings {
860862
enabled: Some(false),
861-
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
863+
disable_on_attributes: None,
864+
disable_on_words: None,
865+
min_word_size_for_typos: None,
862866
};
863867
864868
let task: TaskInfo = client
@@ -874,7 +878,8 @@ typo_tolerance_guide_2: |-
874878
let typo_tolerance = TypoToleranceSettings {
875879
enabled: Some(true),
876880
disable_on_attributes: Some(vec!["title".to_string()]),
877-
min_word_size_for_typos: Some(min_word_size_for_typos),
881+
disable_on_words: None,
882+
min_word_size_for_typos: None,
878883
};
879884
880885
let task: TaskInfo = client
@@ -889,6 +894,7 @@ typo_tolerance_guide_3: |-
889894
}
890895
let typo_tolerance = TypoToleranceSettings {
891896
enabled: Some(true),
897+
disable_on_attributes: None,
892898
disable_on_words: Some(vec!["shrek".to_string()]),
893899
min_word_size_for_typos: Some(min_word_size_for_typos),
894900
};
@@ -905,6 +911,7 @@ typo_tolerance_guide_4: |-
905911
};
906912
let typo_tolerance = TypoToleranceSettings {
907913
enabled: Some(true),
914+
disable_on_attributes: Some(vec![]),
908915
disable_on_words: Some(vec!["title".to_string()]),
909916
min_word_size_for_typos: Some(min_word_size_for_typos),
910917
};

src/settings.rs

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

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

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)]
23+
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
3324
#[serde(rename_all = "camelCase")]
3425
#[serde(default)]
3526
pub struct TypoToleranceSettings {
@@ -39,17 +30,6 @@ pub struct TypoToleranceSettings {
3930
pub min_word_size_for_typos: Option<MinWordSizeForTypos>,
4031
}
4132

42-
impl Default for TypoToleranceSettings {
43-
fn default() -> Self {
44-
TypoToleranceSettings {
45-
enabled: Some(true),
46-
disable_on_attributes: Some(vec![]),
47-
disable_on_words: Some(vec![]),
48-
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
49-
}
50-
}
51-
}
52-
5333
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq, Copy)]
5434
#[serde(rename_all = "camelCase")]
5535
pub struct FacetingSettings {
@@ -123,19 +103,7 @@ pub struct Settings {
123103
impl Settings {
124104
/// Create undefined settings.
125105
pub fn new() -> Settings {
126-
Settings {
127-
synonyms: None,
128-
stop_words: None,
129-
ranking_rules: None,
130-
filterable_attributes: None,
131-
sortable_attributes: None,
132-
distinct_attribute: None,
133-
searchable_attributes: None,
134-
displayed_attributes: None,
135-
pagination: None,
136-
faceting: None,
137-
typo_tolerance: None,
138-
}
106+
Self::default()
139107
}
140108

141109
pub fn with_synonyms<S, U, V>(self, synonyms: HashMap<S, U>) -> Settings
@@ -647,7 +615,7 @@ impl Index {
647615
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
648616
/// #
649617
/// # futures::executor::block_on(async move {
650-
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
618+
/// let client = Client::new(MEILISEARCH_HOST, Some(MEILISEARCH_API_KEY));
651619
/// # client.create_index("get_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
652620
/// let index = client.index("get_typo_tolerance");
653621
/// let typotolerance = index.get_typo_tolerance().await.unwrap();
@@ -1133,7 +1101,7 @@ impl Index {
11331101
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
11341102
/// #
11351103
/// # futures::executor::block_on(async move {
1136-
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1104+
/// let client = Client::new(MEILISEARCH_HOST, Some(MEILISEARCH_API_KEY));
11371105
/// # client.create_index("set_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
11381106
/// let mut index = client.index("set_typo_tolerance");
11391107
///
@@ -1531,7 +1499,7 @@ impl Index {
15311499
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
15321500
/// #
15331501
/// # futures::executor::block_on(async move {
1534-
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1502+
/// let client = Client::new(MEILISEARCH_HOST, Some(MEILISEARCH_API_KEY));
15351503
/// # client.create_index("reset_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
15361504
/// let mut index = client.index("reset_typo_tolerance");
15371505
///
@@ -1654,37 +1622,61 @@ mod tests {
16541622

16551623
#[meilisearch_test]
16561624
async fn test_get_typo_tolerance(index: Index) {
1657-
let typo_tolerance = TypoToleranceSettings::default();
1625+
let expected = TypoToleranceSettings {
1626+
enabled: Some(true),
1627+
disable_on_attributes: Some(vec![]),
1628+
disable_on_words: Some(vec![]),
1629+
min_word_size_for_typos: Some(MinWordSizeForTypos {
1630+
one_typo: Some(5),
1631+
two_typos: Some(9),
1632+
}),
1633+
};
16581634

16591635
let res = index.get_typo_tolerance().await.unwrap();
16601636

1661-
assert_eq!(typo_tolerance, res);
1637+
assert_eq!(expected, res);
16621638
}
16631639

16641640
#[meilisearch_test]
16651641
async fn test_set_typo_tolerance(client: Client, index: Index) {
1666-
let typo_tolerance = TypoToleranceSettings {
1642+
let expected = TypoToleranceSettings {
16671643
enabled: Some(true),
16681644
disable_on_attributes: Some(vec!["title".to_string()]),
16691645
disable_on_words: Some(vec![]),
1670-
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
1646+
min_word_size_for_typos: Some(MinWordSizeForTypos {
1647+
one_typo: Some(5),
1648+
two_typos: Some(9),
1649+
}),
1650+
};
1651+
1652+
let typo_tolerance = TypoToleranceSettings {
1653+
disable_on_attributes: Some(vec!["title".to_string()]),
1654+
..Default::default()
16711655
};
16721656

16731657
let task_info = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
16741658
client.wait_for_task(task_info, None, None).await.unwrap();
16751659

16761660
let res = index.get_typo_tolerance().await.unwrap();
16771661

1678-
assert_eq!(typo_tolerance, res);
1662+
assert_eq!(expected, res);
16791663
}
16801664

16811665
#[meilisearch_test]
16821666
async fn test_reset_typo_tolerance(index: Index) {
1683-
let typo_tolerance = TypoToleranceSettings {
1667+
let expected = TypoToleranceSettings {
16841668
enabled: Some(true),
16851669
disable_on_attributes: Some(vec![]),
1686-
disable_on_words: Some(vec!["title".to_string()]),
1687-
min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
1670+
disable_on_words: Some(vec![]),
1671+
min_word_size_for_typos: Some(MinWordSizeForTypos {
1672+
one_typo: Some(5),
1673+
two_typos: Some(9),
1674+
}),
1675+
};
1676+
1677+
let typo_tolerance = TypoToleranceSettings {
1678+
disable_on_attributes: Some(vec!["title".to_string()]),
1679+
..Default::default()
16881680
};
16891681

16901682
let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
@@ -1695,6 +1687,6 @@ mod tests {
16951687

16961688
let default = index.get_typo_tolerance().await.unwrap();
16971689

1698-
assert_eq!(TypoToleranceSettings::default(), default);
1690+
assert_eq!(expected, default);
16991691
}
17001692
}

0 commit comments

Comments
 (0)