22# Every example written here will be automatically fetched by
33# the documentation on build
44# You can read more on https://github.com/meilisearch/documentation/tree/main/learn
5+ # See the original at https://github.com/meilisearch/documentation/blob/main/.code-samples.meilisearch.yaml
56---
67synonyms_guide_1 : |-
78 let mut synonyms = std::collections::HashMap::new();
@@ -581,8 +582,12 @@ get_faceting_settings_1: |-
581582 .await
582583 .unwrap();
583584update_faceting_settings_1 : |-
585+ let mut facet_sort_setting = BTreeMap::new();
586+ facet_sort_setting.insert(String::from("*"), FacetSortValue::Alpha);
587+ facet_sort_setting.insert(String::from("genres"), FacetSortValue::Count);
584588 let mut faceting = FacetingSettings {
585589 max_values_per_facet: 2,
590+ sort_facet_values_by: Some(facet_sort_setting),
586591 };
587592
588593 let task: TaskInfo = client
@@ -1045,8 +1050,8 @@ primary_field_guide_add_document_primary_key: |-
10451050 ], Some("reference_number"))
10461051 .await
10471052 .unwrap();
1048- getting_started_add_documents_md : |-
1049- ``` toml
1053+ getting_started_add_documents : |-
1054+ // In your . toml file:
10501055 [dependencies]
10511056 meilisearch-sdk = "0.28.0"
10521057 # futures: because we want to block on futures
@@ -1057,9 +1062,8 @@ getting_started_add_documents_md: |-
10571062 serde_json = "1.0"
10581063 ```
10591064
1060- Documents in the Rust library are strongly typed.
1061-
1062- ```rust
1065+ // In your .rs file:
1066+ // Documents in the Rust library are strongly typed
10631067 #[derive(Serialize, Deserialize)]
10641068 struct Movie {
10651069 id: i64,
@@ -1069,23 +1073,17 @@ getting_started_add_documents_md: |-
10691073 release_date: i64,
10701074 genres: Vec<String>
10711075 }
1072- ```
1073-
1074- You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
1075- You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
10761076
1077- ```rust
1077+ // You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
1078+ // You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
10781079 #[derive(Serialize, Deserialize)]
10791080 struct Movie {
10801081 id: i64,
10811082 #[serde(flatten)]
10821083 value: serde_json::Value,
10831084 }
1084- ```
1085-
1086- Then, add documents into the index:
10871085
1088- ```rust
1086+ // Then, add documents into the index:
10891087 use meilisearch_sdk::{
10901088 indexes::*,
10911089 client::*,
@@ -1099,7 +1097,7 @@ getting_started_add_documents_md: |-
10991097 fn main() { block_on(async move {
11001098 let client = Client::new("http://localhost:7700", Some("aSampleMasterKey"));
11011099
1102- // reading and parsing the file
1100+ // Reading and parsing the file
11031101 let mut file = File::open("movies.json")
11041102 .unwrap();
11051103 let mut content = String::new();
@@ -1109,19 +1107,15 @@ getting_started_add_documents_md: |-
11091107 let movies_docs: Vec<Movie> = serde_json::from_str(&content)
11101108 .unwrap();
11111109
1112- // adding documents
1110+ // Adding documents
11131111 client
11141112 .index("movies")
11151113 .add_documents(&movies_docs, None)
11161114 .await
11171115 .unwrap();
11181116 })}
1119- ```
1120-
1121- [About this SDK](https://github.com/meilisearch/meilisearch-rust/)
1122- getting_started_search_md : |-
1123- You can build a `SearchQuery` and execute it later:
1124- ```rust
1117+ getting_started_search : |-
1118+ // You can build a `SearchQuery` and execute it later:
11251119 let query: SearchQuery = SearchQuery::new(&movies)
11261120 .with_query("botman")
11271121 .build();
@@ -1131,29 +1125,22 @@ getting_started_search_md: |-
11311125 .execute_query(&query)
11321126 .await
11331127 .unwrap();
1134- ```
11351128
1136- You can build a `SearchQuery` and execute it directly:
1137- ```rust
1129+ // You can build a `SearchQuery` and execute it directly:
11381130 let results: SearchResults<Movie> = SearchQuery::new(&movies)
11391131 .with_query("botman")
11401132 .execute()
11411133 .await
11421134 .unwrap();
1143- ```
11441135
1145- You can search in an index directly:
1146- ```rust
1136+ // You can search in an index directly:
11471137 let results: SearchResults<Movie> = client
11481138 .index("movies")
11491139 .search()
11501140 .with_query("botman")
11511141 .execute()
11521142 .await
11531143 .unwrap();
1154- ```
1155-
1156- [About this SDK](https://github.com/meilisearch/meilisearch-rust/)
11571144getting_started_update_ranking_rules : |-
11581145 let ranking_rules = [
11591146 "exactness",
@@ -1283,8 +1270,11 @@ getting_started_sorting: |-
12831270 .await
12841271 .unwrap();
12851272getting_started_faceting : |-
1273+ let mut facet_sort_setting = BTreeMap::new();
1274+ facet_sort_setting.insert("*".to_string(), FacetSortValue::Count);
12861275 let mut faceting = FacetingSettings {
12871276 max_values_per_facet: 2,
1277+ sort_facet_values_by: Some(facet_sort_setting),
12881278 };
12891279
12901280 let task: TaskInfo = client
@@ -1650,7 +1640,7 @@ get_experimental_features_1: |-
16501640update_experimental_features_1 : |-
16511641 let client = Client::new("http://localhost:7700", Some("apiKey"));
16521642 let features = ExperimentalFeatures::new(&client);
1653- // update the feature you want here
1643+ features.set_metrics(true)
16541644 let res = features
16551645 .update()
16561646 .await
@@ -1717,6 +1707,33 @@ reset_prefix_search_settings_1: |-
17171707 .reset_prefix_search()
17181708 .await
17191709 .unwrap();
1710+ facet_search_1 : |-
1711+ let res = client.index("books")
1712+ .facet_search("genres")
1713+ .with_facet_query("fiction")
1714+ .with_filter("rating > 3")
1715+ .execute()
1716+ .await
1717+ .unwrap();
1718+ facet_search_2 : |-
1719+ let mut facet_sort_setting = BTreeMap::new();
1720+ facet_sort_setting.insert("genres".to_string(), FacetSortValue::Count);
1721+ let faceting = FacetingSettings {
1722+ max_values_per_facet: 100,
1723+ sort_facet_values_by: Some(facet_sort_setting),
1724+ };
1725+
1726+ let res = client.index("books")
1727+ .set_faceting(&faceting)
1728+ .await
1729+ .unwrap();
1730+ facet_search_3 : |-
1731+ let res = client.index("books")
1732+ .facet_search("genres")
1733+ .with_facet_query("c")
1734+ .execute()
1735+ .await
1736+ .unwrap();
17201737get_search_cutoff_1 : |-
17211738 let search_cutoff_ms: String = client
17221739 .index("movies")
0 commit comments