@@ -98,6 +98,9 @@ pub struct Settings {
98
98
/// Dictionary settings.
99
99
#[ serde( skip_serializing_if = "Option::is_none" ) ]
100
100
pub dictionary : Option < Vec < String > > ,
101
+ /// Proximity precision settings.
102
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
103
+ pub proximity_precision : Option < String > ,
101
104
}
102
105
103
106
#[ allow( missing_docs) ]
@@ -261,6 +264,13 @@ impl Settings {
261
264
..self
262
265
}
263
266
}
267
+
268
+ pub fn with_proximity_precision ( self , proximity_precision : impl AsRef < str > ) -> Settings {
269
+ Settings {
270
+ proximity_precision : Some ( proximity_precision. as_ref ( ) . to_string ( ) ) ,
271
+ ..self
272
+ }
273
+ }
264
274
}
265
275
266
276
impl Index {
@@ -654,6 +664,38 @@ impl Index {
654
664
. await
655
665
}
656
666
667
+ /// Get [proximity_precision](https://www.meilisearch.com/docs/reference/api/settings#proximity-precision) of the [Index].
668
+ ///
669
+ /// # Example
670
+ ///
671
+ /// ```
672
+ /// # use meilisearch_sdk::{client::*, indexes::*};
673
+ /// #
674
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
675
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
676
+ /// #
677
+ /// # futures::executor::block_on(async move {
678
+ /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
679
+ /// # client.create_index("get_proximity_precision", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
680
+ /// let index = client.index("get_proximity_precision");
681
+ ///
682
+ /// let proximity_precision = index.get_proximity_precision().await.unwrap();
683
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
684
+ /// # });
685
+ /// ```
686
+ pub async fn get_proximity_precision ( & self ) -> Result < String , Error > {
687
+ request :: < ( ) , ( ) , String > (
688
+ & format ! (
689
+ "{}/indexes/{}/settings/proximity-precision" ,
690
+ self . client. host, self . uid
691
+ ) ,
692
+ self . client . get_api_key ( ) ,
693
+ Method :: Get { query : ( ) } ,
694
+ 200 ,
695
+ )
696
+ . await
697
+ }
698
+
657
699
/// Get [typo tolerance](https://www.meilisearch.com/docs/learn/configuration/typo_tolerance#typo-tolerance) of the [Index].
658
700
///
659
701
/// ```
@@ -1225,6 +1267,44 @@ impl Index {
1225
1267
. await
1226
1268
}
1227
1269
1270
+ /// Update [proximity-precision](https://www.meilisearch.com/docs/learn/configuration/proximity-precision) settings of the [Index].
1271
+ ///
1272
+ /// # Example
1273
+ ///
1274
+ /// ```
1275
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1276
+ /// #
1277
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1278
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1279
+ /// #
1280
+ /// # futures::executor::block_on(async move {
1281
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
1282
+ /// # client.create_index("set_proximity_precision", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1283
+ /// let mut index = client.index("set_proximity_precision");
1284
+ ///
1285
+ /// let task = index.set_proximity_precision("byWord".to_string()).await.unwrap();
1286
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1287
+ /// # });
1288
+ /// ```
1289
+ pub async fn set_proximity_precision (
1290
+ & self ,
1291
+ proximity_precision : String ,
1292
+ ) -> Result < TaskInfo , Error > {
1293
+ request :: < ( ) , String , TaskInfo > (
1294
+ & format ! (
1295
+ "{}/indexes/{}/settings/proximity-precision" ,
1296
+ self . client. host, self . uid
1297
+ ) ,
1298
+ self . client . get_api_key ( ) ,
1299
+ Method :: Put {
1300
+ query : ( ) ,
1301
+ body : proximity_precision,
1302
+ } ,
1303
+ 202 ,
1304
+ )
1305
+ . await
1306
+ }
1307
+
1228
1308
/// Reset [Settings] of the [Index].
1229
1309
///
1230
1310
/// All settings will be reset to their [default value](https://www.meilisearch.com/docs/reference/api/settings#reset-settings).
@@ -1641,6 +1721,38 @@ impl Index {
1641
1721
)
1642
1722
. await
1643
1723
}
1724
+
1725
+ /// Reset [proximity precision](https://www.meilisearch.com/docs/learn/configuration/typo_tolerance#typo-tolerance) settings of the [Index].
1726
+ ///
1727
+ /// # Example
1728
+ ///
1729
+ /// ```
1730
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1731
+ /// #
1732
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1733
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1734
+ /// #
1735
+ /// # futures::executor::block_on(async move {
1736
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
1737
+ /// # client.create_index("reset_proximity_precision", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1738
+ /// let mut index = client.index("reset_proximity_precision");
1739
+ ///
1740
+ /// let task = index.reset_proximity_precision().await.unwrap();
1741
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1742
+ /// # });
1743
+ /// ```
1744
+ pub async fn reset_proximity_precision ( & self ) -> Result < TaskInfo , Error > {
1745
+ request :: < ( ) , ( ) , TaskInfo > (
1746
+ & format ! (
1747
+ "{}/indexes/{}/settings/proximity-precision" ,
1748
+ self . client. host, self . uid
1749
+ ) ,
1750
+ self . client . get_api_key ( ) ,
1751
+ Method :: Delete { query : ( ) } ,
1752
+ 202 ,
1753
+ )
1754
+ . await
1755
+ }
1644
1756
}
1645
1757
1646
1758
#[ cfg( test) ]
@@ -1853,4 +1965,46 @@ mod tests {
1853
1965
1854
1966
assert_eq ! ( expected, default ) ;
1855
1967
}
1968
+
1969
+ #[ meilisearch_test]
1970
+ async fn test_get_proximity_precision ( index : Index ) {
1971
+ let expected = "byWord" . to_string ( ) ;
1972
+
1973
+ let res = index. get_proximity_precision ( ) . await . unwrap ( ) ;
1974
+
1975
+ assert_eq ! ( expected, res) ;
1976
+ }
1977
+
1978
+ #[ meilisearch_test]
1979
+ async fn test_set_proximity_precision ( client : Client , index : Index ) {
1980
+ let expected = "byAttribute" . to_string ( ) ;
1981
+
1982
+ let task_info = index
1983
+ . set_proximity_precision ( "byAttribute" . to_string ( ) )
1984
+ . await
1985
+ . unwrap ( ) ;
1986
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
1987
+
1988
+ let res = index. get_proximity_precision ( ) . await . unwrap ( ) ;
1989
+
1990
+ assert_eq ! ( expected, res) ;
1991
+ }
1992
+
1993
+ #[ meilisearch_test]
1994
+ async fn test_reset_proximity_precision ( index : Index ) {
1995
+ let expected = "byWord" . to_string ( ) ;
1996
+
1997
+ let task = index
1998
+ . set_proximity_precision ( "byAttribute" . to_string ( ) )
1999
+ . await
2000
+ . unwrap ( ) ;
2001
+ index. wait_for_task ( task, None , None ) . await . unwrap ( ) ;
2002
+
2003
+ let reset_task = index. reset_proximity_precision ( ) . await . unwrap ( ) ;
2004
+ index. wait_for_task ( reset_task, None , None ) . await . unwrap ( ) ;
2005
+
2006
+ let default = index. get_proximity_precision ( ) . await . unwrap ( ) ;
2007
+
2008
+ assert_eq ! ( expected, default ) ;
2009
+ }
1856
2010
}
0 commit comments