@@ -7,6 +7,12 @@ use crate::{
7
7
use serde:: { Deserialize , Serialize } ;
8
8
use std:: collections:: HashMap ;
9
9
10
+ #[ derive( Serialize , Deserialize , Default , Debug , Clone , PartialEq , Eq , Copy ) ]
11
+ #[ serde( rename_all = "camelCase" ) ]
12
+ pub struct PaginationSetting {
13
+ pub max_total_hits : usize
14
+ }
15
+
10
16
#[ derive( Serialize , Deserialize , Default , Debug , Clone , Eq , PartialEq ) ]
11
17
#[ serde( rename_all = "camelCase" ) ]
12
18
pub struct FacetingSettings {
@@ -65,6 +71,9 @@ pub struct Settings {
65
71
/// Fields displayed in the returned documents
66
72
#[ serde( skip_serializing_if = "Option::is_none" ) ]
67
73
pub displayed_attributes : Option < Vec < String > > ,
74
+ /// Pagination settings
75
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
76
+ pub pagination : Option < PaginationSetting > ,
68
77
/// Faceting settings
69
78
#[ serde( skip_serializing_if = "Option::is_none" ) ]
70
79
pub faceting : Option < FacetingSettings > ,
@@ -83,6 +92,7 @@ impl Settings {
83
92
distinct_attribute : None ,
84
93
searchable_attributes : None ,
85
94
displayed_attributes : None ,
95
+ pagination : None ,
86
96
faceting : None ,
87
97
}
88
98
}
@@ -123,6 +133,13 @@ impl Settings {
123
133
}
124
134
}
125
135
136
+ pub fn with_pagination ( self , pagination_settings : PaginationSetting ) -> Settings {
137
+ Settings {
138
+ pagination : Some ( pagination_settings) ,
139
+ ..self
140
+ }
141
+ }
142
+
126
143
pub fn with_ranking_rules (
127
144
self ,
128
145
ranking_rules : impl IntoIterator < Item = impl AsRef < str > > ,
@@ -272,6 +289,35 @@ impl Index {
272
289
. await
273
290
}
274
291
292
+ /// Get [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
293
+ ///
294
+ /// ```
295
+ /// # use meilisearch_sdk::{client::*, indexes::*};
296
+ /// #
297
+ /// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
298
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
299
+ /// #
300
+ /// # futures::executor::block_on(async move {
301
+ /// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
302
+ /// # client.create_index("get_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
303
+ /// let index = client.index("get_pagination");
304
+ /// let pagination = index.get_pagination().await.unwrap();
305
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
306
+ /// # });
307
+ /// ```
308
+ pub async fn get_pagination ( & self ) -> Result < PaginationSetting , Error > {
309
+ request :: < ( ) , PaginationSetting > (
310
+ & format ! (
311
+ "{}/indexes/{}/settings/pagination" ,
312
+ self . client. host, self . uid
313
+ ) ,
314
+ & self . client . api_key ,
315
+ Method :: Get ( ( ) ) ,
316
+ 200 ,
317
+ )
318
+ . await
319
+ }
320
+
275
321
/// Get [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
276
322
///
277
323
/// ```
@@ -510,7 +556,7 @@ impl Index {
510
556
/// # Example
511
557
///
512
558
/// ```
513
- /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
559
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::{ Settings, PaginationSetting} };
514
560
/// #
515
561
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
516
562
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
@@ -522,7 +568,9 @@ impl Index {
522
568
///
523
569
/// let stop_words = vec![String::from("a"), String::from("the"), String::from("of")];
524
570
/// let settings = Settings::new()
525
- /// .with_stop_words(stop_words.clone());
571
+ /// .with_stop_words(stop_words.clone())
572
+ /// .with_pagination(PaginationSetting {max_total_hits: 100}
573
+ /// );
526
574
///
527
575
/// let task = index.set_settings(&settings).await.unwrap();
528
576
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
@@ -578,6 +626,38 @@ impl Index {
578
626
. await
579
627
}
580
628
629
+ /// Update [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
630
+ ///
631
+ /// # Example
632
+ ///
633
+ /// ```
634
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::{Settings, PaginationSetting}};
635
+ /// #
636
+ /// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
637
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
638
+ /// #
639
+ /// # futures::executor::block_on(async move {
640
+ /// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
641
+ /// # client.create_index("set_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
642
+ /// let mut index = client.index("set_pagination");
643
+ /// let pagination = PaginationSetting {max_total_hits:100};
644
+ /// let task = index.set_pagination(pagination).await.unwrap();
645
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
646
+ /// # });
647
+ /// ```
648
+ pub async fn set_pagination ( & self , pagination : PaginationSetting , ) -> Result < TaskInfo , Error > {
649
+ request :: < & PaginationSetting , TaskInfo > (
650
+ & format ! (
651
+ "{}/indexes/{}/settings/pagination" ,
652
+ self . client. host, self . uid
653
+ ) ,
654
+ & self . client . api_key ,
655
+ Method :: Patch ( & pagination) ,
656
+ 202 ,
657
+ )
658
+ . await
659
+ }
660
+
581
661
/// Update [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
582
662
///
583
663
/// # Example
@@ -967,6 +1047,37 @@ impl Index {
967
1047
. await
968
1048
}
969
1049
1050
+ /// Reset [pagination](https://docs.meilisearch.com/learn/configuration/settings.html#pagination) of the [Index].
1051
+ ///
1052
+ /// # Example
1053
+ ///
1054
+ /// ```
1055
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1056
+ /// #
1057
+ /// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
1058
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1059
+ /// #
1060
+ /// # futures::executor::block_on(async move {
1061
+ /// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1062
+ /// # client.create_index("reset_pagination", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1063
+ /// let mut index = client.index("reset_pagination");
1064
+ ///
1065
+ /// let task = index.reset_pagination().await.unwrap();
1066
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1067
+ /// # });
1068
+ /// ```
1069
+ pub async fn reset_pagination ( & self ) -> Result < TaskInfo , Error > {
1070
+ request :: < ( ) , TaskInfo > (
1071
+ & format ! (
1072
+ "{}/indexes/{}/settings/pagination" ,
1073
+ self . client. host, self . uid
1074
+ ) ,
1075
+ & self . client . api_key ,
1076
+ Method :: Delete ,
1077
+ 202 ,
1078
+ )
1079
+ . await
1080
+ }
970
1081
/// Reset [stop-words](https://docs.meilisearch.com/reference/features/stop_words.html) of the [Index].
971
1082
///
972
1083
/// # Example
@@ -1285,4 +1396,46 @@ mod tests {
1285
1396
1286
1397
assert_eq ! ( faceting, res) ;
1287
1398
}
1399
+
1400
+ #[ meilisearch_test]
1401
+ async fn test_get_pagination ( index : Index ) {
1402
+ let pagination = PaginationSetting {
1403
+ max_total_hits : 1000 ,
1404
+ } ;
1405
+
1406
+ let res = index. get_pagination ( ) . await . unwrap ( ) ;
1407
+
1408
+ assert_eq ! ( pagination, res) ;
1409
+ }
1410
+
1411
+ #[ meilisearch_test]
1412
+ async fn test_set_pagination ( index : Index ) {
1413
+ let pagination = PaginationSetting {
1414
+ max_total_hits : 11 ,
1415
+ } ;
1416
+ let task = index. set_pagination ( pagination) . await . unwrap ( ) ;
1417
+ index. wait_for_task ( task, None , None ) . await . unwrap ( ) ;
1418
+
1419
+ let res = index. get_pagination ( ) . await . unwrap ( ) ;
1420
+
1421
+ assert_eq ! ( pagination, res) ;
1422
+ }
1423
+
1424
+ #[ meilisearch_test]
1425
+ async fn test_reset_pagination ( index : Index ) {
1426
+ let pagination = PaginationSetting {
1427
+ max_total_hits : 10 ,
1428
+ } ;
1429
+ let default = PaginationSetting { max_total_hits : 1000 } ;
1430
+
1431
+ let task = index. set_pagination ( pagination) . await . unwrap ( ) ;
1432
+ index. wait_for_task ( task, None , None ) . await . unwrap ( ) ;
1433
+
1434
+ let reset_task = index. reset_pagination ( ) . await . unwrap ( ) ;
1435
+ index. wait_for_task ( reset_task, None , None ) . await . unwrap ( ) ;
1436
+
1437
+ let res = index. get_pagination ( ) . await . unwrap ( ) ;
1438
+
1439
+ assert_eq ! ( default , res) ;
1440
+ }
1288
1441
}
0 commit comments