use std::collections::{BTreeMap, BTreeSet}; use serde::{Deserialize, Serialize}; #[derive(Default, Clone, Serialize, Deserialize)] pub struct Settings { pub ranking_rules: Option>, pub ranking_distinct: Option, pub attribute_identifier: Option, pub attributes_searchable: Option>, pub attributes_displayed: Option>, pub attributes_ranked: Option>, pub stop_words: Option>, pub synonyms: Option>>, } impl Into for Settings { fn into(self) -> SettingsUpdate { let settings = self.clone(); SettingsUpdate { ranking_rules: settings.ranking_rules.into(), ranking_distinct: settings.ranking_distinct.into(), attribute_identifier: settings.attribute_identifier.into(), attributes_searchable: settings.attributes_searchable.into(), attributes_displayed: settings.attributes_displayed.into(), attributes_ranked: settings.attributes_ranked.into(), stop_words: settings.stop_words.into(), synonyms: settings.synonyms.into(), } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub enum UpdateState { Update(T), Add(T), Delete(T), Clear, Nothing, } impl From> for UpdateState { fn from(opt: Option) -> UpdateState { match opt { Some(t) => UpdateState::Update(t), None => UpdateState::Nothing, } } } impl UpdateState { pub fn is_changed(&self) -> bool { match self { UpdateState::Nothing => false, _ => true, } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SettingsUpdate { pub ranking_rules: UpdateState>, pub ranking_distinct: UpdateState, pub attribute_identifier: UpdateState, pub attributes_searchable: UpdateState>, pub attributes_displayed: UpdateState>, pub attributes_ranked: UpdateState>, pub stop_words: UpdateState>, pub synonyms: UpdateState>>, } impl Default for SettingsUpdate { fn default() -> Self { Self { ranking_rules: UpdateState::Nothing, ranking_distinct: UpdateState::Nothing, attribute_identifier: UpdateState::Nothing, attributes_searchable: UpdateState::Nothing, attributes_displayed: UpdateState::Nothing, attributes_ranked: UpdateState::Nothing, stop_words: UpdateState::Nothing, synonyms: UpdateState::Nothing, } } }