Make sure that the order of the sortableAttributes is constant

This commit is contained in:
Kerollmops 2021-08-26 11:06:04 +02:00
parent 64462c842b
commit 087e4626ce
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 11 additions and 6 deletions

View File

@ -57,7 +57,7 @@ pub struct Settings<T> {
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
pub filterable_attributes: Setting<HashSet<String>>, pub filterable_attributes: Setting<HashSet<String>>,
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
pub sortable_attributes: Setting<HashSet<String>>, pub sortable_attributes: Setting<BTreeSet<String>>,
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
pub ranking_rules: Setting<Vec<String>>, pub ranking_rules: Setting<Vec<String>>,
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
@ -254,14 +254,19 @@ impl Index {
} }
match settings.filterable_attributes { match settings.filterable_attributes {
Setting::Set(ref facet_types) => builder.set_filterable_fields(facet_types.clone()), Setting::Set(ref facets) => builder.set_filterable_fields(facets.clone()),
Setting::Reset => builder.set_filterable_fields(HashSet::new()), Setting::Reset => builder.reset_filterable_fields(),
Setting::NotSet => (), Setting::NotSet => (),
} }
match settings.sortable_attributes { match settings.sortable_attributes {
Setting::Set(ref facet_types) => builder.set_sortable_fields(facet_types.clone()), Setting::Set(ref fields) => {
Setting::Reset => builder.set_sortable_fields(HashSet::new()), builder.set_sortable_fields(fields.iter().cloned().collect())
}
Setting::Reset => {
// TODO we must use the reset_sortable_fields in a futur PR.
builder.set_sortable_fields(HashSet::new())
}
Setting::NotSet => (), Setting::NotSet => (),
} }

View File

@ -82,7 +82,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/sortable-attributes", "/sortable-attributes",
std::collections::HashSet<String>, std::collections::BTreeSet<String>,
sortable_attributes, sortable_attributes,
"sortableAttributes" "sortableAttributes"
); );