@@ -106,6 +106,12 @@ pub struct Settings {
106
106
/// SearchCutoffMs settings.
107
107
#[ serde( skip_serializing_if = "Option::is_none" ) ]
108
108
pub search_cutoff_ms : Option < u64 > ,
109
+ /// Configure strings as custom separator tokens indicating where a word ends and begins.
110
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
111
+ pub separator_tokens : Option < Vec < String > > ,
112
+ /// Remove tokens from Meilisearch's default [list of word separators](https://www.meilisearch.com/docs/learn/engine/datatypes#string).
113
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
114
+ pub non_separator_tokens : Option < Vec < String > > ,
109
115
}
110
116
111
117
#[ allow( missing_docs) ]
@@ -298,6 +304,38 @@ impl Settings {
298
304
..self
299
305
}
300
306
}
307
+
308
+ #[ must_use]
309
+ pub fn with_separation_tokens (
310
+ self ,
311
+ separator_tokens : impl IntoIterator < Item = impl AsRef < str > > ,
312
+ ) -> Settings {
313
+ Settings {
314
+ separator_tokens : Some (
315
+ separator_tokens
316
+ . into_iter ( )
317
+ . map ( |v| v. as_ref ( ) . to_string ( ) )
318
+ . collect ( ) ,
319
+ ) ,
320
+ ..self
321
+ }
322
+ }
323
+
324
+ #[ must_use]
325
+ pub fn with_non_separation_tokens (
326
+ self ,
327
+ non_separator_tokens : impl IntoIterator < Item = impl AsRef < str > > ,
328
+ ) -> Settings {
329
+ Settings {
330
+ non_separator_tokens : Some (
331
+ non_separator_tokens
332
+ . into_iter ( )
333
+ . map ( |v| v. as_ref ( ) . to_string ( ) )
334
+ . collect ( ) ,
335
+ ) ,
336
+ ..self
337
+ }
338
+ }
301
339
}
302
340
303
341
impl < Http : HttpClient > Index < Http > {
@@ -800,6 +838,68 @@ impl<Http: HttpClient> Index<Http> {
800
838
. await
801
839
}
802
840
841
+ /// Get [separator token](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) of the [Index].
842
+ ///
843
+ /// ```
844
+ /// # use meilisearch_sdk::{client::*, indexes::*};
845
+ /// #
846
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
847
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
848
+ /// #
849
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
850
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
851
+ /// # client.create_index("get_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
852
+ /// let index = client.index("get_separator_tokens");
853
+ ///
854
+ /// let separator_tokens = index.get_separator_tokens().await.unwrap();
855
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
856
+ /// # });
857
+ /// ```
858
+ pub async fn get_separator_tokens ( & self ) -> Result < Vec < String > , Error > {
859
+ self . client
860
+ . http_client
861
+ . request :: < ( ) , ( ) , Vec < String > > (
862
+ & format ! (
863
+ "{}/indexes/{}/settings/separator-tokens" ,
864
+ self . client. host, self . uid
865
+ ) ,
866
+ Method :: Get { query : ( ) } ,
867
+ 200 ,
868
+ )
869
+ . await
870
+ }
871
+
872
+ /// Get [non separator token](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) of the [Index].
873
+ ///
874
+ /// ```
875
+ /// # use meilisearch_sdk::{client::*, indexes::*};
876
+ /// #
877
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
878
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
879
+ /// #
880
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
881
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
882
+ /// # client.create_index("get_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
883
+ /// let index = client.index("get_non_separator_tokens");
884
+ ///
885
+ /// let non_separator_tokens = index.get_non_separator_tokens().await.unwrap();
886
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
887
+ /// # });
888
+ /// ```
889
+ pub async fn get_non_separator_tokens ( & self ) -> Result < Vec < String > , Error > {
890
+ self . client
891
+ . http_client
892
+ . request :: < ( ) , ( ) , Vec < String > > (
893
+ & format ! (
894
+ "{}/indexes/{}/settings/non-separator-tokens" ,
895
+ self . client. host, self . uid
896
+ ) ,
897
+ Method :: Get { query : ( ) } ,
898
+ 200 ,
899
+ )
900
+ . await
901
+ }
902
+
803
903
/// Update [settings](../settings/struct.Settings) of the [Index].
804
904
///
805
905
/// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged.
@@ -1354,6 +1454,88 @@ impl<Http: HttpClient> Index<Http> {
1354
1454
. await
1355
1455
}
1356
1456
1457
+ /// Update [separator tokens](https://www.meilisearch.com/docs/reference/api/settings#separator-tokens) settings of the [Index].
1458
+ ///
1459
+ /// # Example
1460
+ ///
1461
+ /// ```
1462
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::{TypoToleranceSettings, MinWordSizeForTypos}};
1463
+ /// #
1464
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1465
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1466
+ /// #
1467
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
1468
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
1469
+ /// # client.create_index("set_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1470
+ /// let mut index = client.index("set_separator_tokens");
1471
+ ///
1472
+ /// let separator_token: Vec<String> = vec!["@".to_string(), "#".to_string()];
1473
+ ///
1474
+ /// let task = index.set_separator_tokens(&separator_token).await.unwrap();
1475
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1476
+ /// # });
1477
+ /// ```
1478
+ pub async fn set_separator_tokens (
1479
+ & self ,
1480
+ separator_token : & Vec < String > ,
1481
+ ) -> Result < TaskInfo , Error > {
1482
+ self . client
1483
+ . http_client
1484
+ . request :: < ( ) , & Vec < String > , TaskInfo > (
1485
+ & format ! (
1486
+ "{}/indexes/{}/settings/separator-tokens" ,
1487
+ self . client. host, self . uid
1488
+ ) ,
1489
+ Method :: Put {
1490
+ query : ( ) ,
1491
+ body : separator_token,
1492
+ } ,
1493
+ 202 ,
1494
+ )
1495
+ . await
1496
+ }
1497
+
1498
+ /// Update [non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) settings of the [Index].
1499
+ ///
1500
+ /// # Example
1501
+ ///
1502
+ /// ```
1503
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::{TypoToleranceSettings, MinWordSizeForTypos}};
1504
+ /// #
1505
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1506
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1507
+ /// #
1508
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
1509
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
1510
+ /// # client.create_index("set_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1511
+ /// let mut index = client.index("set_non_separator_tokens");
1512
+ ///
1513
+ /// let non_separator_token: Vec<String> = vec!["@".to_string(), "#".to_string()];
1514
+ ///
1515
+ /// let task = index.set_non_separator_tokens(&non_separator_token).await.unwrap();
1516
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1517
+ /// # });
1518
+ /// ```
1519
+ pub async fn set_non_separator_tokens (
1520
+ & self ,
1521
+ non_separator_token : & Vec < String > ,
1522
+ ) -> Result < TaskInfo , Error > {
1523
+ self . client
1524
+ . http_client
1525
+ . request :: < ( ) , & Vec < String > , TaskInfo > (
1526
+ & format ! (
1527
+ "{}/indexes/{}/settings/non-separator-tokens" ,
1528
+ self . client. host, self . uid
1529
+ ) ,
1530
+ Method :: Put {
1531
+ query : ( ) ,
1532
+ body : non_separator_token,
1533
+ } ,
1534
+ 202 ,
1535
+ )
1536
+ . await
1537
+ }
1538
+
1357
1539
/// Update [proximity-precision](https://www.meilisearch.com/docs/learn/configuration/proximity-precision) settings of the [Index].
1358
1540
///
1359
1541
/// # Example
@@ -1924,6 +2106,72 @@ impl<Http: HttpClient> Index<Http> {
1924
2106
)
1925
2107
. await
1926
2108
}
2109
+
2110
+ /// Reset [search cutoff](https://www.meilisearch.com/docs/reference/api/settings#search-cutoff) settings of the [Index].
2111
+ ///
2112
+ /// # Example
2113
+ ///
2114
+ /// ```
2115
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
2116
+ /// #
2117
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
2118
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
2119
+ /// #
2120
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
2121
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
2122
+ /// # client.create_index("reset_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2123
+ /// let mut index = client.index("reset_separator_tokens");
2124
+ ///
2125
+ /// let task = index.reset_separator_tokens().await.unwrap();
2126
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2127
+ /// # });
2128
+ /// ```
2129
+ pub async fn reset_separator_tokens ( & self ) -> Result < TaskInfo , Error > {
2130
+ self . client
2131
+ . http_client
2132
+ . request :: < ( ) , ( ) , TaskInfo > (
2133
+ & format ! (
2134
+ "{}/indexes/{}/settings/separator-tokens" ,
2135
+ self . client. host, self . uid
2136
+ ) ,
2137
+ Method :: Delete { query : ( ) } ,
2138
+ 202 ,
2139
+ )
2140
+ . await
2141
+ }
2142
+
2143
+ /// Reset [non separator tokens](https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens) settings of the [Index].
2144
+ ///
2145
+ /// # Example
2146
+ ///
2147
+ /// ```
2148
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
2149
+ /// #
2150
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
2151
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
2152
+ /// #
2153
+ /// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
2154
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
2155
+ /// # client.create_index("reset_non_separator_tokens", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2156
+ /// let mut index = client.index("reset_non_separator_tokens");
2157
+ ///
2158
+ /// let task = index.reset_non_separator_tokens().await.unwrap();
2159
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
2160
+ /// # });
2161
+ /// ```
2162
+ pub async fn reset_non_separator_tokens ( & self ) -> Result < TaskInfo , Error > {
2163
+ self . client
2164
+ . http_client
2165
+ . request :: < ( ) , ( ) , TaskInfo > (
2166
+ & format ! (
2167
+ "{}/indexes/{}/settings/non-separator-tokens" ,
2168
+ self . client. host, self . uid
2169
+ ) ,
2170
+ Method :: Delete { query : ( ) } ,
2171
+ 202 ,
2172
+ )
2173
+ . await
2174
+ }
1927
2175
}
1928
2176
1929
2177
#[ cfg( test) ]
@@ -2200,6 +2448,26 @@ mod tests {
2200
2448
assert_eq ! ( expected, res) ;
2201
2449
}
2202
2450
2451
+ #[ meilisearch_test]
2452
+ async fn test_get_separator_tokens ( index : Index ) {
2453
+ let separator: Vec < & str > = vec ! [ ] ;
2454
+ let res = index. get_separator_tokens ( ) . await . unwrap ( ) ;
2455
+
2456
+ assert_eq ! ( separator, res) ;
2457
+ }
2458
+
2459
+ #[ meilisearch_test]
2460
+ async fn test_set_separator_tokens ( client : Client , index : Index ) {
2461
+ let expected: Vec < String > = vec ! [ "#" . to_string( ) , "@" . to_string( ) ] ;
2462
+
2463
+ let task_info = index. set_separator_tokens ( & expected) . await . unwrap ( ) ;
2464
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2465
+
2466
+ let res = index. get_separator_tokens ( ) . await . unwrap ( ) ;
2467
+
2468
+ assert_eq ! ( expected, res) ;
2469
+ }
2470
+
2203
2471
#[ meilisearch_test]
2204
2472
async fn test_reset_search_cutoff_ms ( index : Index ) {
2205
2473
let expected = None ;
@@ -2214,4 +2482,44 @@ mod tests {
2214
2482
2215
2483
assert_eq ! ( expected, default ) ;
2216
2484
}
2485
+
2486
+ #[ meilisearch_test]
2487
+ async fn test_reset_separator_tokens ( client : Client , index : Index ) {
2488
+ let separator: Vec < & str > = vec ! [ ] ;
2489
+ let task_info = index. reset_separator_tokens ( ) . await . unwrap ( ) ;
2490
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2491
+
2492
+ let res = index. get_dictionary ( ) . await . unwrap ( ) ;
2493
+ assert_eq ! ( separator, res) ;
2494
+ }
2495
+
2496
+ #[ meilisearch_test]
2497
+ async fn test_get_non_separator_tokens ( index : Index ) {
2498
+ let separator: Vec < & str > = vec ! [ ] ;
2499
+ let res = index. get_non_separator_tokens ( ) . await . unwrap ( ) ;
2500
+
2501
+ assert_eq ! ( separator, res) ;
2502
+ }
2503
+
2504
+ #[ meilisearch_test]
2505
+ async fn test_set_non_separator_tokens ( client : Client , index : Index ) {
2506
+ let expected: Vec < String > = vec ! [ "#" . to_string( ) , "@" . to_string( ) ] ;
2507
+
2508
+ let task_info = index. set_non_separator_tokens ( & expected) . await . unwrap ( ) ;
2509
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2510
+
2511
+ let res = index. get_non_separator_tokens ( ) . await . unwrap ( ) ;
2512
+
2513
+ assert_eq ! ( expected, res) ;
2514
+ }
2515
+
2516
+ #[ meilisearch_test]
2517
+ async fn test_reset_non_separator_tokens ( client : Client , index : Index ) {
2518
+ let separator: Vec < & str > = vec ! [ ] ;
2519
+ let task_info = index. reset_non_separator_tokens ( ) . await . unwrap ( ) ;
2520
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2521
+
2522
+ let res = index. get_dictionary ( ) . await . unwrap ( ) ;
2523
+ assert_eq ! ( separator, res) ;
2524
+ }
2217
2525
}
0 commit comments