mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-25 06:00:08 +01:00
Merge #330
330: Introduce the reset_sortable_fields Settings method r=irevoire a=Kerollmops I forgot to add the `reset_sortable_fields` method on the `Settings` builder, it is no big deal as the library user (like MeiliSearch) can always call `set_sortable_fields` with an empty list of fields, it is equivalent. Co-authored-by: Kerollmops <clement@meilisearch.com> Co-authored-by: Tamo <tamo@meilisearch.com> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
This commit is contained in:
commit
df38794c7d
@ -257,6 +257,9 @@ struct Settings {
|
|||||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||||
filterable_attributes: Setting<HashSet<String>>,
|
filterable_attributes: Setting<HashSet<String>>,
|
||||||
|
|
||||||
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||||
|
sortable_attributes: Setting<HashSet<String>>,
|
||||||
|
|
||||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||||
criteria: Setting<Vec<String>>,
|
criteria: Setting<Vec<String>>,
|
||||||
|
|
||||||
@ -448,6 +451,15 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
Setting::NotSet => (),
|
Setting::NotSet => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We transpose the settings JSON struct into a real setting update.
|
||||||
|
match settings.sortable_attributes {
|
||||||
|
Setting::Set(sortable_attributes) => {
|
||||||
|
builder.set_sortable_fields(sortable_attributes)
|
||||||
|
}
|
||||||
|
Setting::Reset => builder.reset_sortable_fields(),
|
||||||
|
Setting::NotSet => (),
|
||||||
|
}
|
||||||
|
|
||||||
// We transpose the settings JSON struct into a real setting update.
|
// We transpose the settings JSON struct into a real setting update.
|
||||||
match settings.criteria {
|
match settings.criteria {
|
||||||
Setting::Set(criteria) => builder.set_criteria(criteria),
|
Setting::Set(criteria) => builder.set_criteria(criteria),
|
||||||
@ -1029,6 +1041,7 @@ mod tests {
|
|||||||
displayed_attributes: Setting::Set(vec!["name".to_string()]),
|
displayed_attributes: Setting::Set(vec!["name".to_string()]),
|
||||||
searchable_attributes: Setting::Set(vec!["age".to_string()]),
|
searchable_attributes: Setting::Set(vec!["age".to_string()]),
|
||||||
filterable_attributes: Setting::Set(hashset! { "age".to_string() }),
|
filterable_attributes: Setting::Set(hashset! { "age".to_string() }),
|
||||||
|
sortable_attributes: Setting::Set(hashset! { "age".to_string() }),
|
||||||
criteria: Setting::Set(vec!["age:asc".to_string()]),
|
criteria: Setting::Set(vec!["age:asc".to_string()]),
|
||||||
stop_words: Setting::Set(btreeset! { "and".to_string() }),
|
stop_words: Setting::Set(btreeset! { "and".to_string() }),
|
||||||
synonyms: Setting::Set(hashmap! { "alex".to_string() => vec!["alexey".to_string()] }),
|
synonyms: Setting::Set(hashmap! { "alex".to_string() => vec!["alexey".to_string()] }),
|
||||||
@ -1037,7 +1050,7 @@ mod tests {
|
|||||||
assert_tokens(
|
assert_tokens(
|
||||||
&settings,
|
&settings,
|
||||||
&[
|
&[
|
||||||
Token::Struct { name: "Settings", len: 6 },
|
Token::Struct { name: "Settings", len: 7 },
|
||||||
Token::Str("displayedAttributes"),
|
Token::Str("displayedAttributes"),
|
||||||
Token::Some,
|
Token::Some,
|
||||||
Token::Seq { len: Some(1) },
|
Token::Seq { len: Some(1) },
|
||||||
@ -1048,12 +1061,16 @@ mod tests {
|
|||||||
Token::Seq { len: Some(1) },
|
Token::Seq { len: Some(1) },
|
||||||
Token::Str("age"),
|
Token::Str("age"),
|
||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
Token::Str("facetedAttributes"),
|
Token::Str("filterableAttributes"),
|
||||||
Token::Some,
|
Token::Some,
|
||||||
Token::Map { len: Some(1) },
|
Token::Seq { len: Some(1) },
|
||||||
Token::Str("age"),
|
Token::Str("age"),
|
||||||
Token::Str("integer"),
|
Token::SeqEnd,
|
||||||
Token::MapEnd,
|
Token::Str("sortableAttributes"),
|
||||||
|
Token::Some,
|
||||||
|
Token::Seq { len: Some(1) },
|
||||||
|
Token::Str("age"),
|
||||||
|
Token::SeqEnd,
|
||||||
Token::Str("criteria"),
|
Token::Str("criteria"),
|
||||||
Token::Some,
|
Token::Some,
|
||||||
Token::Seq { len: Some(1) },
|
Token::Seq { len: Some(1) },
|
||||||
@ -1083,6 +1100,7 @@ mod tests {
|
|||||||
displayed_attributes: Setting::Reset,
|
displayed_attributes: Setting::Reset,
|
||||||
searchable_attributes: Setting::Reset,
|
searchable_attributes: Setting::Reset,
|
||||||
filterable_attributes: Setting::Reset,
|
filterable_attributes: Setting::Reset,
|
||||||
|
sortable_attributes: Setting::Reset,
|
||||||
criteria: Setting::Reset,
|
criteria: Setting::Reset,
|
||||||
stop_words: Setting::Reset,
|
stop_words: Setting::Reset,
|
||||||
synonyms: Setting::Reset,
|
synonyms: Setting::Reset,
|
||||||
@ -1091,12 +1109,14 @@ mod tests {
|
|||||||
assert_tokens(
|
assert_tokens(
|
||||||
&settings,
|
&settings,
|
||||||
&[
|
&[
|
||||||
Token::Struct { name: "Settings", len: 6 },
|
Token::Struct { name: "Settings", len: 7 },
|
||||||
Token::Str("displayedAttributes"),
|
Token::Str("displayedAttributes"),
|
||||||
Token::None,
|
Token::None,
|
||||||
Token::Str("searchableAttributes"),
|
Token::Str("searchableAttributes"),
|
||||||
Token::None,
|
Token::None,
|
||||||
Token::Str("facetedAttributes"),
|
Token::Str("filterableAttributes"),
|
||||||
|
Token::None,
|
||||||
|
Token::Str("sortableAttributes"),
|
||||||
Token::None,
|
Token::None,
|
||||||
Token::Str("criteria"),
|
Token::Str("criteria"),
|
||||||
Token::None,
|
Token::None,
|
||||||
@ -1115,6 +1135,7 @@ mod tests {
|
|||||||
displayed_attributes: Setting::NotSet,
|
displayed_attributes: Setting::NotSet,
|
||||||
searchable_attributes: Setting::NotSet,
|
searchable_attributes: Setting::NotSet,
|
||||||
filterable_attributes: Setting::NotSet,
|
filterable_attributes: Setting::NotSet,
|
||||||
|
sortable_attributes: Setting::NotSet,
|
||||||
criteria: Setting::NotSet,
|
criteria: Setting::NotSet,
|
||||||
stop_words: Setting::NotSet,
|
stop_words: Setting::NotSet,
|
||||||
synonyms: Setting::NotSet,
|
synonyms: Setting::NotSet,
|
||||||
|
@ -141,6 +141,10 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||||||
self.sortable_fields = Setting::Set(names);
|
self.sortable_fields = Setting::Set(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_sortable_fields(&mut self) {
|
||||||
|
self.sortable_fields = Setting::Reset;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn reset_criteria(&mut self) {
|
pub fn reset_criteria(&mut self) {
|
||||||
self.criteria = Setting::Reset;
|
self.criteria = Setting::Reset;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user