@@ -98,6 +98,9 @@ pub struct Settings {
9898 /// Dictionary settings.
9999 #[ serde( skip_serializing_if = "Option::is_none" ) ]
100100 pub dictionary : Option < Vec < String > > ,
101+ /// Proximity precision settings.
102+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
103+ pub proximity_precision : Option < String > ,
101104}
102105
103106#[ allow( missing_docs) ]
@@ -261,6 +264,13 @@ impl Settings {
261264 ..self
262265 }
263266 }
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+ }
264274}
265275
266276impl Index {
@@ -654,6 +664,38 @@ impl Index {
654664 . await
655665 }
656666
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+
657699 /// Get [typo tolerance](https://www.meilisearch.com/docs/learn/configuration/typo_tolerance#typo-tolerance) of the [Index].
658700 ///
659701 /// ```
@@ -1225,6 +1267,44 @@ impl Index {
12251267 . await
12261268 }
12271269
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+
12281308 /// Reset [Settings] of the [Index].
12291309 ///
12301310 /// 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 {
16411721 )
16421722 . await
16431723 }
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+ }
16441756}
16451757
16461758#[ cfg( test) ]
@@ -1853,4 +1965,46 @@ mod tests {
18531965
18541966 assert_eq ! ( expected, default ) ;
18551967 }
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+ }
18562010}
0 commit comments