@@ -13,23 +13,14 @@ pub struct PaginationSetting {
13
13
pub max_total_hits : usize ,
14
14
}
15
15
16
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Eq ) ]
16
+ #[ derive( Serialize , Deserialize , Default , Debug , Clone , PartialEq , Eq ) ]
17
17
#[ serde( rename_all = "camelCase" ) ]
18
18
pub struct MinWordSizeForTypos {
19
19
pub one_typo : Option < u8 > ,
20
20
pub two_typos : Option < u8 > ,
21
21
}
22
22
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 ) ]
33
24
#[ serde( rename_all = "camelCase" ) ]
34
25
#[ serde( default ) ]
35
26
pub struct TypoToleranceSettings {
@@ -39,17 +30,6 @@ pub struct TypoToleranceSettings {
39
30
pub min_word_size_for_typos : Option < MinWordSizeForTypos > ,
40
31
}
41
32
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
-
53
33
#[ derive( Serialize , Deserialize , Default , Debug , Clone , Eq , PartialEq , Copy ) ]
54
34
#[ serde( rename_all = "camelCase" ) ]
55
35
pub struct FacetingSettings {
@@ -123,19 +103,7 @@ pub struct Settings {
123
103
impl Settings {
124
104
/// Create undefined settings.
125
105
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 ( )
139
107
}
140
108
141
109
pub fn with_synonyms < S , U , V > ( self , synonyms : HashMap < S , U > ) -> Settings
@@ -647,7 +615,7 @@ impl Index {
647
615
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
648
616
/// #
649
617
/// # 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) );
651
619
/// # client.create_index("get_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
652
620
/// let index = client.index("get_typo_tolerance");
653
621
/// let typotolerance = index.get_typo_tolerance().await.unwrap();
@@ -1133,7 +1101,7 @@ impl Index {
1133
1101
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1134
1102
/// #
1135
1103
/// # 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) );
1137
1105
/// # client.create_index("set_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1138
1106
/// let mut index = client.index("set_typo_tolerance");
1139
1107
///
@@ -1531,7 +1499,7 @@ impl Index {
1531
1499
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1532
1500
/// #
1533
1501
/// # 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) );
1535
1503
/// # client.create_index("reset_typo_tolerance", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1536
1504
/// let mut index = client.index("reset_typo_tolerance");
1537
1505
///
@@ -1654,37 +1622,61 @@ mod tests {
1654
1622
1655
1623
#[ meilisearch_test]
1656
1624
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
+ } ;
1658
1634
1659
1635
let res = index. get_typo_tolerance ( ) . await . unwrap ( ) ;
1660
1636
1661
- assert_eq ! ( typo_tolerance , res) ;
1637
+ assert_eq ! ( expected , res) ;
1662
1638
}
1663
1639
1664
1640
#[ meilisearch_test]
1665
1641
async fn test_set_typo_tolerance ( client : Client , index : Index ) {
1666
- let typo_tolerance = TypoToleranceSettings {
1642
+ let expected = TypoToleranceSettings {
1667
1643
enabled : Some ( true ) ,
1668
1644
disable_on_attributes : Some ( vec ! [ "title" . to_string( ) ] ) ,
1669
1645
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 ( )
1671
1655
} ;
1672
1656
1673
1657
let task_info = index. set_typo_tolerance ( & typo_tolerance) . await . unwrap ( ) ;
1674
1658
client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
1675
1659
1676
1660
let res = index. get_typo_tolerance ( ) . await . unwrap ( ) ;
1677
1661
1678
- assert_eq ! ( typo_tolerance , res) ;
1662
+ assert_eq ! ( expected , res) ;
1679
1663
}
1680
1664
1681
1665
#[ meilisearch_test]
1682
1666
async fn test_reset_typo_tolerance ( index : Index ) {
1683
- let typo_tolerance = TypoToleranceSettings {
1667
+ let expected = TypoToleranceSettings {
1684
1668
enabled : Some ( true ) ,
1685
1669
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 ( )
1688
1680
} ;
1689
1681
1690
1682
let task = index. set_typo_tolerance ( & typo_tolerance) . await . unwrap ( ) ;
@@ -1695,6 +1687,6 @@ mod tests {
1695
1687
1696
1688
let default = index. get_typo_tolerance ( ) . await . unwrap ( ) ;
1697
1689
1698
- assert_eq ! ( TypoToleranceSettings :: default ( ) , default ) ;
1690
+ assert_eq ! ( expected , default ) ;
1699
1691
}
1700
1692
}
0 commit comments