Skip to content

Commit c6023d5

Browse files
bors[bot]Mubelotix
andauthored
Merge #112
112: Improve settings r=curquiza a=Mubelotix Allow users to use a variety of data types when constructing `Settings` with the builder syntax. Fix #38. Co-authored-by: Mubelotix <[email protected]>
2 parents a78ec53 + 6bee8ea commit c6023d5

File tree

3 files changed

+183
-99
lines changed

3 files changed

+183
-99
lines changed

.code-samples.meilisearch.yaml

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,37 @@ get_settings_1: |-
6969
let settings: Settings = movies.get_settings().await.unwrap();
7070
update_settings_1: |-
7171
let mut synonyms = std::collections::HashMap::new();
72-
synonyms.insert(String::from("wolverine"), vec![String::from("xmen"), String::from("logan")]);
73-
synonyms.insert(String::from("logan"), vec![String::from("wolverine")]);
72+
synonyms.insert(String::from("wolverine"), vec!["xmen", "logan"]);
73+
synonyms.insert(String::from("logan"), vec!["wolverine"]);
7474
7575
let settings = Settings::new()
76-
.with_ranking_rules(vec![
77-
"typo".to_string(),
78-
"words".to_string(),
79-
"proximity".to_string(),
80-
"attribute".to_string(),
81-
"wordsPosition".to_string(),
82-
"exactness".to_string(),
83-
"desc(release_date)".to_string(),
84-
"desc(rank)".to_string()
85-
])
86-
.with_distinct_attribute("movie_id".to_string())
87-
.with_searchable_attributes(vec![
88-
"title".to_string(),
89-
"description".to_string(),
90-
"genre".to_string()
91-
])
92-
.with_displayed_attributes(vec![
93-
"title".to_string(),
94-
"description".to_string(),
95-
"genre".to_string(),
96-
"release_date".to_string()
97-
])
98-
.with_stop_words(vec![
99-
"the".to_string(),
100-
"a".to_string(),
101-
"an".to_string()
102-
])
76+
.with_ranking_rules(&[
77+
"typo",
78+
"words",
79+
"proximity",
80+
"attribute",
81+
"wordsPosition",
82+
"exactness",
83+
"desc(release_date)",
84+
"desc(rank)"
85+
][..])
86+
.with_distinct_attribute("movie_id")
87+
.with_searchable_attributes(&[
88+
"title",
89+
"description",
90+
"genre"
91+
][..])
92+
.with_displayed_attributes(&[
93+
"title",
94+
"description",
95+
"genre",
96+
"release_date"
97+
][..])
98+
.with_stop_words(&[
99+
"the",
100+
"a",
101+
"an"
102+
][..])
103103
.with_synonyms(synonyms);
104104
105105
let progress: Progress = movies.set_settings(&settings).await.unwrap();
@@ -119,14 +119,14 @@ reset_synonyms_1: |-
119119
get_stop_words_1: |-
120120
let stop_words: Vec<String> = movies.get_stop_words().await.unwrap();
121121
update_stop_words_1: |-
122-
let stop_words = &["of", "the", "to"];
123-
let progress: Progress = movies.set_stop_words(stop_words).await.unwrap();
122+
let stop_words = ["of", "the", "to"];
123+
let progress: Progress = movies.set_stop_words(&stop_words[..]).await.unwrap();
124124
reset_stop_words_1: |-
125125
let progress: Progress = movies.reset_stop_words().await.unwrap();
126126
get_ranking_rules_1: |-
127127
let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();
128128
update_ranking_rules_1: |-
129-
let ranking_rules = &[
129+
let ranking_rules = [
130130
"typo",
131131
"words",
132132
"proximity",
@@ -137,7 +137,7 @@ update_ranking_rules_1: |-
137137
"desc(rank)",
138138
];
139139
140-
let progress: Progress = movies.set_ranking_rules(ranking_rules).await.unwrap();
140+
let progress: Progress = movies.set_ranking_rules(&ranking_rules[..]).await.unwrap();
141141
reset_ranking_rules_1: |-
142142
let progress: Progress = movies.reset_ranking_rules().await.unwrap();
143143
get_distinct_attribute_1: |-
@@ -149,37 +149,37 @@ reset_distinct_attribute_1: |-
149149
get_searchable_attributes_1: |-
150150
let searchable_attributes: Vec<String> = movies.get_searchable_attributes().await.unwrap();
151151
update_searchable_attributes_1: |-
152-
let searchable_attributes = &[
152+
let searchable_attributes = [
153153
"title",
154154
"description",
155155
"genre"
156156
];
157157
158-
let progress: Progress = movies.set_searchable_attributes(searchable_attributes).await.unwrap();
158+
let progress: Progress = movies.set_searchable_attributes(&searchable_attributes[..]).await.unwrap();
159159
reset_searchable_attributes_1: |-
160160
let progress: Progress = movies.reset_searchable_attributes().await.unwrap();
161161
get_attributes_for_faceting_1: |-
162162
let attributes_for_faceting: Vec<String> = movies.get_attributes_for_faceting().await.unwrap();
163163
update_attributes_for_faceting_1: |-
164-
let attributes_for_faceting = &[
164+
let attributes_for_faceting = [
165165
"genres",
166166
"director"
167167
];
168168
169-
let progress: Progress = movies.set_attributes_for_faceting(attributes_for_faceting).await.unwrap();
169+
let progress: Progress = movies.set_attributes_for_faceting(&attributes_for_faceting[..]).await.unwrap();
170170
reset_attributes_for_faceting_1: |-
171171
let progress: Progress = movies.reset_attributes_for_faceting().await.unwrap();
172172
get_displayed_attributes_1: |-
173173
let displayed_attributes: Vec<String> = movies.get_displayed_attributes().await.unwrap();
174174
update_displayed_attributes_1: |-
175-
let displayed_attributes = &[
175+
let displayed_attributes = [
176176
"title",
177177
"description",
178178
"genre",
179179
"release_date"
180180
];
181181
182-
let progress: Progress = movies.set_displayed_attributes(displayed_attributes).await.unwrap();
182+
let progress: Progress = movies.set_displayed_attributes(&displayed_attributes[..]).await.unwrap();
183183
reset_displayed_attributes_1: |-
184184
let progress: Progress = movies.reset_displayed_attributes().await.unwrap();
185185
get_index_stats_1: |-
@@ -195,22 +195,22 @@ distinct_attribute_guide_1: |-
195195
let jackets: Index = client.get_index("jackets").await.unwrap();
196196
let progress: Progress = jackets.set_distinct_attribute("product_id").await.unwrap();
197197
field_properties_guide_searchable_1: |-
198-
let searchable_attributes = &[
198+
let searchable_attributes = [
199199
"title",
200200
"description",
201201
"genre"
202202
];
203203
204-
let progress: Progress = movies.set_searchable_attributes(searchable_attributes).await.unwrap();
204+
let progress: Progress = movies.set_searchable_attributes(&searchable_attributes[..]).await.unwrap();
205205
field_properties_guide_displayed_1: |-
206-
let displayed_attributes = &[
206+
let displayed_attributes = [
207207
"title",
208208
"description",
209209
"genre",
210210
"release_date"
211211
];
212212
213-
let progress: Progress = movies.set_displayed_attributes(displayed_attributes).await.unwrap();
213+
let progress: Progress = movies.set_displayed_attributes(&displayed_attributes[..]).await.unwrap();
214214
filtering_guide_1: |-
215215
let results: SearchResults<Movie> = movies.search()
216216
.with_query("Avengers")
@@ -321,11 +321,11 @@ settings_guide_synonyms_1: |-
321321
let tops: Index = client.get_index("tops").await.unwrap();
322322
let progress: Progress = tops.set_synonyms(&synonyms).await.unwrap();
323323
settings_guide_stop_words_1: |-
324-
let progress: Progress = movies.set_stop_words(&["the", "a", "an"]).await.unwrap();
324+
let progress: Progress = movies.set_stop_words(&["the", "a", "an"][..]).await.unwrap();
325325
settings_guide_attributes_for_faceting_1: |-
326-
let progress: Progress = movies.set_attributes_for_faceting(&["director", "genres"]).await.unwrap();
326+
let progress: Progress = movies.set_attributes_for_faceting(&["director", "genres"][..]).await.unwrap();
327327
settings_guide_ranking_rules_1: |-
328-
let ranking_rules = &[
328+
let ranking_rules = [
329329
"typo",
330330
"words",
331331
"proximity",
@@ -336,27 +336,27 @@ settings_guide_ranking_rules_1: |-
336336
"desc(rank)",
337337
];
338338
339-
let progress: Progress = movies.set_ranking_rules(ranking_rules).await.unwrap();
339+
let progress: Progress = movies.set_ranking_rules(&ranking_rules[..]).await.unwrap();
340340
settings_guide_distinct_1: |-
341341
let jackets: Index = client.get_index("jackets").await.unwrap();
342342
let progress: Progress = jackets.set_distinct_attribute("product_id").await.unwrap();
343343
settings_guide_searchable_1: |-
344-
let searchable_attributes = &[
344+
let searchable_attributes = [
345345
"title",
346346
"description",
347347
"genre"
348348
];
349349
350-
let progress: Progress = movies.set_searchable_attributes(searchable_attributes).await.unwrap();
350+
let progress: Progress = movies.set_searchable_attributes(&searchable_attributes[..]).await.unwrap();
351351
settings_guide_displayed_1: |-
352-
let displayed_attributes = &[
352+
let displayed_attributes = [
353353
"title",
354354
"description",
355355
"genre",
356356
"release_date"
357357
];
358358
359-
let progress: Progress = movies.set_displayed_attributes(displayed_attributes).await.unwrap();
359+
let progress: Progress = movies.set_displayed_attributes(&displayed_attributes[..]).await.unwrap();
360360
documents_guide_add_movie_1: |-
361361
// Define the type of our documents
362362
#[derive(Serialize, Deserialize, Debug)]
@@ -500,7 +500,7 @@ getting_started_search_md: |-
500500
501501
[About this package](https://github.com/meilisearch/meilisearch-rust/)
502502
faceted_search_update_settings_1: |-
503-
let progress: Progress = movies.set_attributes_for_faceting(&["director", "genres"]).await.unwrap();
503+
let progress: Progress = movies.set_attributes_for_faceting(&["director", "genres"][..]).await.unwrap();
504504
faceted_search_facet_filters_1: |-
505505
let results: SearchResults<Movie> = movies.search()
506506
.with_query("thriller")
@@ -517,7 +517,14 @@ faceted_search_facets_distribution_1: |-
517517
.unwrap();
518518
let genres: &HashMap<String, usize> = results.facets_distribution.unwrap().get("genres").unwrap();
519519
faceted_search_walkthrough_attributes_for_faceting_1: |-
520-
let progress: Progress = movies.set_attributes_for_faceting(&["director", "producer", "genres", "production_companies"]).await.unwrap();
520+
let attributes_for_faceting = [
521+
"director",
522+
"producer",
523+
"genres",
524+
"production_companies"
525+
];
526+
527+
let progress: Progress = movies.set_attributes_for_faceting(&attributes_for_faceting[..]).await.unwrap();
521528
faceted_search_walkthrough_facet_filters_1: |-
522529
let results: SearchResults<Movie> = movies.search()
523530
.with_query("thriller")

src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ mod tests {
322322
Document { id: 8, kind: "title".into(), value: "Harry Potter and the Half-Blood Prince".to_string() },
323323
Document { id: 9, kind: "title".into(), value: "Harry Potter and the Deathly Hallows".to_string() },
324324
], None).await.unwrap();
325-
index.set_attributes_for_faceting(&["kind"]).await.unwrap();
325+
index.set_attributes_for_faceting(&["kind"][..]).await.unwrap();
326326
sleep(Duration::from_secs(1));
327327
index
328328
}

0 commit comments

Comments
 (0)