Skip to content

Commit 043a553

Browse files
Merge #576
576: with_distrinct_attribute accepts None r=irevoire a=NoodleSamaChan # Pull Request ## Related issue Fixes #368 ## What does this PR do? - changed with_distinct_attribute so that it accepts None ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: NoodleSamaChan <[email protected]> Co-authored-by: NoodleSamaChan <[email protected]>
2 parents 76fb43f + 031b779 commit 043a553

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

.code-samples.meilisearch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ update_settings_1: |-
315315
"release_date:desc",
316316
"rank:desc"
317317
])
318-
.with_distinct_attribute("movie_id")
318+
.with_distinct_attribute(Some("movie_id"))
319319
.with_searchable_attributes([
320320
"title",
321321
"overview",

meilisearch-index-setting-macro/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ fn get_index_config_implementation(
123123
get_settings_token_for_list(&filterable_attributes, "with_filterable_attributes");
124124
let searchable_attr_tokens =
125125
get_settings_token_for_list(&searchable_attributes, "with_searchable_attributes");
126-
let distinct_attr_token =
127-
get_settings_token_for_string(&distinct_key_attribute, "with_distinct_attribute");
126+
let distinct_attr_token = get_settings_token_for_string_for_some_string(
127+
&distinct_key_attribute,
128+
"with_distinct_attribute",
129+
);
128130

129131
quote! {
130132
#[::meilisearch_sdk::macro_helper::async_trait(?Send)]
@@ -173,7 +175,7 @@ fn get_settings_token_for_list(
173175
}
174176
}
175177

176-
fn get_settings_token_for_string(
178+
fn get_settings_token_for_string_for_some_string(
177179
field_name: &String,
178180
method_name: &str,
179181
) -> proc_macro2::TokenStream {
@@ -183,7 +185,7 @@ fn get_settings_token_for_string(
183185
proc_macro2::TokenStream::new()
184186
} else {
185187
quote! {
186-
.#method_ident(#field_name)
188+
.#method_ident(::std::option::Option::Some(#field_name))
187189
}
188190
}
189191
}

src/settings.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct Settings {
8181
pub sortable_attributes: Option<Vec<String>>,
8282
/// Search returns documents with distinct (different) values of the given field.
8383
#[serde(skip_serializing_if = "Option::is_none")]
84-
pub distinct_attribute: Option<String>,
84+
pub distinct_attribute: Option<Option<String>>,
8585
/// Fields in which to search for matching query words sorted by order of importance.
8686
#[serde(skip_serializing_if = "Option::is_none")]
8787
pub searchable_attributes: Option<Vec<String>>,
@@ -217,9 +217,11 @@ impl Settings {
217217
}
218218

219219
#[must_use]
220-
pub fn with_distinct_attribute(self, distinct_attribute: impl AsRef<str>) -> Settings {
220+
pub fn with_distinct_attribute(self, distinct_attribute: Option<impl AsRef<str>>) -> Settings {
221221
Settings {
222-
distinct_attribute: Some(distinct_attribute.as_ref().to_string()),
222+
distinct_attribute: Some(
223+
distinct_attribute.map(|distinct| distinct.as_ref().to_string()),
224+
),
223225
..self
224226
}
225227
}

0 commit comments

Comments
 (0)