Skip to content

Commit 6bee8ea

Browse files
committed
Extend to settings setters
1 parent c42af04 commit 6bee8ea

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

.code-samples.meilisearch.yaml

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/settings.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct Settings {
5252
pub displayed_attributes: Option<Vec<String>>,
5353
}
5454

55-
pub trait IntoVecString {
55+
pub trait IntoVecString: Sized {
5656
fn convert(self) -> Vec<String>;
5757
}
5858

@@ -410,17 +410,17 @@ impl<'a> Index<'a> {
410410
/// let client = Client::new("http://localhost:7700", "masterKey");
411411
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
412412
///
413-
/// let stop_words = &["the", "of", "to"];
414-
/// let progress = movie_index.set_stop_words(stop_words).await.unwrap();
413+
/// let stop_words = ["the", "of", "to"];
414+
/// let progress = movie_index.set_stop_words(&stop_words[..]).await.unwrap();
415415
/// # std::thread::sleep(std::time::Duration::from_secs(2));
416416
/// # progress.get_status().await.unwrap();
417417
/// # });
418418
/// ```
419-
pub async fn set_stop_words(&'a self, stop_words: &[&str]) -> Result<Progress<'a>, Error> {
420-
Ok(request::<&[&str], ProgressJson>(
419+
pub async fn set_stop_words(&'a self, stop_words: impl IntoVecString) -> Result<Progress<'a>, Error> {
420+
Ok(request::<Vec<String>, ProgressJson>(
421421
&format!("{}/indexes/{}/settings/stop-words", self.client.host, self.uid),
422422
self.client.apikey,
423-
Method::Post(stop_words),
423+
Method::Post(stop_words.convert()),
424424
202,
425425
).await?
426426
.into_progress(self))
@@ -436,7 +436,7 @@ impl<'a> Index<'a> {
436436
/// let client = Client::new("http://localhost:7700", "masterKey");
437437
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
438438
///
439-
/// let ranking_rules = &[
439+
/// let ranking_rules = [
440440
/// "typo",
441441
/// "words",
442442
/// "proximity",
@@ -446,16 +446,16 @@ impl<'a> Index<'a> {
446446
/// "asc(release_date)",
447447
/// "desc(rank)",
448448
/// ];
449-
/// let progress = movie_index.set_ranking_rules(ranking_rules).await.unwrap();
449+
/// let progress = movie_index.set_ranking_rules(&ranking_rules[..]).await.unwrap();
450450
/// # std::thread::sleep(std::time::Duration::from_secs(2));
451451
/// # progress.get_status().await.unwrap();
452452
/// # });
453453
/// ```
454-
pub async fn set_ranking_rules(&'a self, ranking_rules: &[&str]) -> Result<Progress<'a>, Error> {
455-
Ok(request::<&[&str], ProgressJson>(
454+
pub async fn set_ranking_rules(&'a self, ranking_rules: impl IntoVecString) -> Result<Progress<'a>, Error> {
455+
Ok(request::<Vec<String>, ProgressJson>(
456456
&format!("{}/indexes/{}/settings/ranking-rules", self.client.host, self.uid),
457457
self.client.apikey,
458-
Method::Post(ranking_rules),
458+
Method::Post(ranking_rules.convert()),
459459
202,
460460
).await?
461461
.into_progress(self))
@@ -471,17 +471,17 @@ impl<'a> Index<'a> {
471471
/// let client = Client::new("http://localhost:7700", "masterKey");
472472
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
473473
///
474-
/// let attributes_for_faceting = &["genre", "director"];
475-
/// let progress = movie_index.set_attributes_for_faceting(attributes_for_faceting).await.unwrap();
474+
/// let attributes_for_faceting = ["genre", "director"];
475+
/// let progress = movie_index.set_attributes_for_faceting(&attributes_for_faceting[..]).await.unwrap();
476476
/// # std::thread::sleep(std::time::Duration::from_secs(2));
477477
/// # progress.get_status().await.unwrap();
478478
/// # });
479479
/// ```
480-
pub async fn set_attributes_for_faceting(&'a self, attributes_for_faceting: &[&str]) -> Result<Progress<'a>, Error> {
481-
Ok(request::<&[&str], ProgressJson>(
480+
pub async fn set_attributes_for_faceting(&'a self, attributes_for_faceting: impl IntoVecString) -> Result<Progress<'a>, Error> {
481+
Ok(request::<Vec<String>, ProgressJson>(
482482
&format!("{}/indexes/{}/settings/attributes-for-faceting", self.client.host, self.uid),
483483
self.client.apikey,
484-
Method::Post(attributes_for_faceting),
484+
Method::Post(attributes_for_faceting.convert()),
485485
202,
486486
).await?
487487
.into_progress(self))
@@ -502,11 +502,11 @@ impl<'a> Index<'a> {
502502
/// # progress.get_status().await.unwrap();
503503
/// # });
504504
/// ```
505-
pub async fn set_distinct_attribute(&'a self, distinct_attribute: &str) -> Result<Progress<'a>, Error> {
506-
Ok(request::<&str, ProgressJson>(
505+
pub async fn set_distinct_attribute(&'a self, distinct_attribute: impl Into<String>) -> Result<Progress<'a>, Error> {
506+
Ok(request::<String, ProgressJson>(
507507
&format!("{}/indexes/{}/settings/distinct-attribute", self.client.host, self.uid),
508508
self.client.apikey,
509-
Method::Post(distinct_attribute),
509+
Method::Post(distinct_attribute.into()),
510510
202,
511511
).await?
512512
.into_progress(self))
@@ -522,16 +522,16 @@ impl<'a> Index<'a> {
522522
/// let client = Client::new("http://localhost:7700", "masterKey");
523523
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
524524
///
525-
/// let progress = movie_index.set_searchable_attributes(&["title", "description", "uid"]).await.unwrap();
525+
/// let progress = movie_index.set_searchable_attributes(&["title", "description", "uid"][..]).await.unwrap();
526526
/// # std::thread::sleep(std::time::Duration::from_secs(2));
527527
/// # progress.get_status().await.unwrap();
528528
/// # });
529529
/// ```
530-
pub async fn set_searchable_attributes(&'a self, searchable_attributes: &[&str]) -> Result<Progress<'a>, Error> {
531-
Ok(request::<&[&str], ProgressJson>(
530+
pub async fn set_searchable_attributes(&'a self, searchable_attributes: impl IntoVecString) -> Result<Progress<'a>, Error> {
531+
Ok(request::<Vec<String>, ProgressJson>(
532532
&format!("{}/indexes/{}/settings/searchable-attributes", self.client.host, self.uid),
533533
self.client.apikey,
534-
Method::Post(searchable_attributes),
534+
Method::Post(searchable_attributes.convert()),
535535
202,
536536
).await?
537537
.into_progress(self))
@@ -547,16 +547,16 @@ impl<'a> Index<'a> {
547547
/// let client = Client::new("http://localhost:7700", "masterKey");
548548
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
549549
///
550-
/// let progress = movie_index.set_displayed_attributes(&["title", "description", "release_date", "rank", "poster"]).await.unwrap();
550+
/// let progress = movie_index.set_displayed_attributes(&["title", "description", "release_date", "rank", "poster"][..]).await.unwrap();
551551
/// # std::thread::sleep(std::time::Duration::from_secs(2));
552552
/// # progress.get_status().await.unwrap();
553553
/// # });
554554
/// ```
555-
pub async fn set_displayed_attributes(&'a self, displayed_attributes: &[&str]) -> Result<Progress<'a>, Error> {
556-
Ok(request::<&[&str], ProgressJson>(
555+
pub async fn set_displayed_attributes(&'a self, displayed_attributes: impl IntoVecString) -> Result<Progress<'a>, Error> {
556+
Ok(request::<Vec<String>, ProgressJson>(
557557
&format!("{}/indexes/{}/settings/displayed-attributes", self.client.host, self.uid),
558558
self.client.apikey,
559-
Method::Post(displayed_attributes),
559+
Method::Post(displayed_attributes.convert()),
560560
202,
561561
).await?
562562
.into_progress(self))

0 commit comments

Comments
 (0)