Skip to content

Commit 8d69be5

Browse files
authored
Merge branch 'main' into add-with-array-filter
2 parents 9b7d208 + bdd5f5a commit 8d69be5

File tree

7 files changed

+245
-2
lines changed

7 files changed

+245
-2
lines changed

.code-samples.meilisearch.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ reset_displayed_attributes_1: |-
358358
.reset_displayed_attributes()
359359
.await
360360
.unwrap();
361+
get_faceting_settings_1: |-
362+
let faceting: FacetingSettings = client
363+
.index("books")
364+
.get_faceting()
365+
.await
366+
.unwrap();
367+
update_faceting_settings_1: |-
368+
let mut faceting = FacetingSettings {
369+
max_values_per_facet: 2,
370+
};
371+
372+
let task: TaskInfo = client
373+
.index("books")
374+
.set_faceting(&faceting)
375+
.await
376+
.unwrap();
377+
reset_faceting_settings_1: |-
378+
let task: TaskInfo = client
379+
.index("books")
380+
.reset_faceting()
381+
.await
382+
.unwrap();
361383
get_index_stats_1: |-
362384
let stats: IndexStats = client
363385
.index("movies")
@@ -661,6 +683,18 @@ settings_guide_sortable_1: |-
661683
.set_settings(&settings)
662684
.await
663685
.unwrap();
686+
settings_guide_faceting_1: |-
687+
let faceting = FacetingSettings {
688+
max_values_per_facet: 5,
689+
};
690+
let settings = Settings::new()
691+
.with_faceting(&faceting);
692+
693+
let task: TaskInfo = client
694+
.index("movies")
695+
.set_settings(&settings)
696+
.await
697+
.unwrap();
664698
add_movies_json_1: |-
665699
use meilisearch_sdk::{
666700
indexes::*,
@@ -987,6 +1021,16 @@ getting_started_sorting: |-
9871021
.execute()
9881022
.await
9891023
.unwrap();
1024+
getting_started_faceting: |-
1025+
let mut faceting = FacetingSettings {
1026+
max_values_per_facet: 2,
1027+
};
1028+
1029+
let task: TaskInfo = client
1030+
.index("movies")
1031+
.set_faceting(&faceting)
1032+
.await
1033+
.unwrap();
9901034
getting_started_filtering: |-
9911035
let results: SearchResults<Meteorite> = client
9921036
.index("meteorites")

.github/workflows/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ jobs:
4444
# Will fail when encountering warnings
4545
run: cargo clippy -- -D warnings
4646

47+
formatter:
48+
name: rust-format
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- name: Run formatter
53+
run: cargo fmt
54+
4755
readme_check:
4856
name: readme-check
4957
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ It's [Hacktoberfest month](https://hacktoberfest.com)! 🥳
1616

1717
Thanks so much for participating with Meilisearch this year!
1818

19-
1. We will follow the quality standards set by the organizers of Hacktoberfest (see detail on their [website](https://hacktoberfest.digitalocean.com/resources/qualitystandards)). Our reviewers will not consider any PR that doesn’t match that standard.
19+
1. We will follow the quality standards set by the organizers of Hacktoberfest (see detail on their [website](https://hacktoberfest.com/participation/#spam)). Our reviewers will not consider any PR that doesn’t match that standard.
2020
2. PRs reviews will take place from Monday to Thursday, during usual working hours, CEST time. If you submit outside of these hours, there’s no need to panic; we will get around to your contribution.
2121
3. There will be no issue assignment as we don’t want people to ask to be assigned specific issues and never return, discouraging the volunteer contributors from opening a PR to fix this issue. We take the liberty to choose the PR that best fixes the issue, so we encourage you to get to it as soon as possible and do your best!
2222

bors.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
status = [
22
'integration-tests',
33
'clippy-check',
4+
'rust-format',
45
'readme-check',
56
'wasm-build'
67
]

src/dumps.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@ mod tests {
122122
Ok(())
123123
}
124124
}
125+

src/indexes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,13 @@ impl Index {
611611
} else {
612612
format!("{}/indexes/{}/documents", self.client.host, self.uid)
613613
};
614-
request::<&[T], TaskInfo>(&url, &self.client.api_key, Method::Put(documents), 202).await
614+
request::<&[T], TaskInfo>(
615+
&url,
616+
&self.client.api_key,
617+
Method::Put(documents),
618+
202
619+
)
620+
.await
615621
}
616622

617623
/// Delete all documents in the index.

src/settings.rs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ use crate::{
77
use serde::{Deserialize, Serialize};
88
use std::collections::HashMap;
99

10+
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]
11+
#[serde(rename_all = "camelCase")]
12+
pub struct FacetingSettings {
13+
#[serde()]
14+
pub max_values_per_facet: usize,
15+
}
16+
1017
/// Struct reprensenting a set of settings.
1118
/// You can build this struct using the builder syntax.
1219
///
@@ -58,6 +65,9 @@ pub struct Settings {
5865
/// Fields displayed in the returned documents
5966
#[serde(skip_serializing_if = "Option::is_none")]
6067
pub displayed_attributes: Option<Vec<String>>,
68+
/// Faceting settings
69+
#[serde(skip_serializing_if = "Option::is_none")]
70+
pub faceting: Option<FacetingSettings>,
6171
}
6272

6373
#[allow(missing_docs)]
@@ -73,6 +83,7 @@ impl Settings {
7383
distinct_attribute: None,
7484
searchable_attributes: None,
7585
displayed_attributes: None,
86+
faceting: None,
7687
}
7788
}
7889
pub fn with_synonyms<S, U, V>(self, synonyms: HashMap<S, U>) -> Settings
@@ -193,6 +204,16 @@ impl Settings {
193204
..self
194205
}
195206
}
207+
208+
pub fn with_faceting(
209+
self,
210+
faceting: &FacetingSettings,
211+
) -> Settings {
212+
Settings {
213+
faceting: Some(faceting.clone()),
214+
..self
215+
}
216+
}
196217
}
197218

198219
impl Index {
@@ -454,6 +475,35 @@ impl Index {
454475
.await
455476
}
456477

478+
/// Get [faceting](https://docs.meilisearch.com/reference/api/settings.html#faceting) settings of the [Index].
479+
///
480+
/// ```
481+
/// # use meilisearch_sdk::{client::*, indexes::*};
482+
/// #
483+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
484+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
485+
/// #
486+
/// # futures::executor::block_on(async move {
487+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
488+
/// # client.create_index("get_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
489+
/// let index = client.index("get_faceting");
490+
/// let faceting = index.get_faceting().await.unwrap();
491+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
492+
/// # });
493+
/// ```
494+
pub async fn get_faceting(&self) -> Result<FacetingSettings, Error> {
495+
request::<(), FacetingSettings>(
496+
&format!(
497+
"{}/indexes/{}/settings/faceting",
498+
self.client.host, self.uid
499+
),
500+
&self.client.api_key,
501+
Method::Get(()),
502+
200,
503+
)
504+
.await
505+
}
506+
457507
/// Update [settings](../settings/struct.Settings.html) of the [Index].
458508
/// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged.
459509
///
@@ -816,6 +866,45 @@ impl Index {
816866
.await
817867
}
818868

869+
/// Update [faceting](https://docs.meilisearch.com/reference/api/settings.html#faceting) settings of the [Index].
870+
///
871+
/// # Example
872+
///
873+
/// ```
874+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings, settings::FacetingSettings};
875+
/// #
876+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
877+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
878+
/// #
879+
/// # futures::executor::block_on(async move {
880+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
881+
/// # client.create_index("set_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
882+
/// let mut index = client.index("set_faceting");
883+
///
884+
/// let mut faceting = FacetingSettings {
885+
/// max_values_per_facet: 12,
886+
/// };
887+
///
888+
/// let task = index.set_faceting(&faceting).await.unwrap();
889+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
890+
/// # });
891+
/// ```
892+
pub async fn set_faceting(
893+
&self,
894+
faceting: &FacetingSettings,
895+
) -> Result<TaskInfo, Error> {
896+
request::<&FacetingSettings, TaskInfo>(
897+
&format!(
898+
"{}/indexes/{}/settings/faceting",
899+
self.client.host, self.uid
900+
),
901+
&self.client.api_key,
902+
Method::Patch(faceting),
903+
202,
904+
)
905+
.await
906+
}
907+
819908
/// Reset [Settings] of the [Index].
820909
/// All settings will be reset to their [default value](https://docs.meilisearch.com/reference/api/settings.html#reset-settings).
821910
///
@@ -1102,4 +1191,98 @@ impl Index {
11021191
)
11031192
.await
11041193
}
1194+
1195+
/// Reset [faceting](https://docs.meilisearch.com/reference/api/settings.html#faceting) settings of the [Index].
1196+
///
1197+
/// # Example
1198+
///
1199+
/// ```
1200+
/// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1201+
/// #
1202+
/// # let MEILISEARCH_HOST = option_env!("MEILISEARCH_HOST").unwrap_or("http://localhost:7700");
1203+
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1204+
/// #
1205+
/// # futures::executor::block_on(async move {
1206+
/// let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
1207+
/// # client.create_index("reset_faceting", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1208+
/// let mut index = client.index("reset_faceting");
1209+
///
1210+
/// let task = index.reset_faceting().await.unwrap();
1211+
/// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1212+
/// # });
1213+
/// ```
1214+
pub async fn reset_faceting(&self) -> Result<TaskInfo, Error> {
1215+
request::<(), TaskInfo>(
1216+
&format!(
1217+
"{}/indexes/{}/settings/faceting",
1218+
self.client.host, self.uid
1219+
),
1220+
&self.client.api_key,
1221+
Method::Delete,
1222+
202,
1223+
)
1224+
.await
1225+
}
1226+
}
1227+
1228+
1229+
#[cfg(test)]
1230+
mod tests {
1231+
use super::*;
1232+
1233+
use crate::client::*;
1234+
use meilisearch_test_macro::meilisearch_test;
1235+
1236+
#[meilisearch_test]
1237+
async fn test_set_faceting_settings(client: Client, index: Index) {
1238+
let faceting = FacetingSettings {
1239+
max_values_per_facet: 5,
1240+
};
1241+
let settings = Settings::new()
1242+
.with_faceting(&faceting);
1243+
1244+
let task_info = index.set_settings(&settings).await.unwrap();
1245+
client.wait_for_task(task_info, None, None).await.unwrap();
1246+
1247+
let res = index.get_faceting().await.unwrap();
1248+
1249+
assert_eq!(faceting, res);
1250+
}
1251+
1252+
#[meilisearch_test]
1253+
async fn test_get_faceting(index: Index) {
1254+
let faceting = FacetingSettings {
1255+
max_values_per_facet: 100,
1256+
};
1257+
1258+
let res = index.get_faceting().await.unwrap();
1259+
1260+
assert_eq!(faceting, res);
1261+
}
1262+
1263+
#[meilisearch_test]
1264+
async fn test_set_faceting(client: Client, index: Index) {
1265+
let faceting = FacetingSettings {
1266+
max_values_per_facet: 5,
1267+
};
1268+
let task_info = index.set_faceting(&faceting).await.unwrap();
1269+
client.wait_for_task(task_info, None, None).await.unwrap();
1270+
1271+
let res = index.get_faceting().await.unwrap();
1272+
1273+
assert_eq!(faceting, res);
1274+
}
1275+
1276+
#[meilisearch_test]
1277+
async fn test_reset_faceting(client: Client, index: Index) {
1278+
let task_info = index.reset_faceting().await.unwrap();
1279+
client.wait_for_task(task_info, None, None).await.unwrap();
1280+
let faceting = FacetingSettings {
1281+
max_values_per_facet: 100,
1282+
};
1283+
1284+
let res = index.get_faceting().await.unwrap();
1285+
1286+
assert_eq!(faceting, res);
1287+
}
11051288
}

0 commit comments

Comments
 (0)