From 6deb4815898a21b8bbd21220922170a0da232e7a Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Sun, 19 Jan 2020 10:58:16 +0100 Subject: [PATCH] definitely remove attributes_ranked on settings; auto create it with ranking_rules --- meilisearch-core/src/database.rs | 12 +++++++-- meilisearch-core/src/settings.rs | 13 ++++++--- .../src/update/settings_update.rs | 27 ++++--------------- meilisearch-http/src/routes/setting.rs | 7 ----- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 3f02f63ff..2203c0084 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -973,10 +973,18 @@ mod tests { let settings = { let data = r#" { + "ranking_rules": [ + "_typo", + "_words", + "_proximity", + "_attribute", + "_words_position", + "_exact", + "dsc(release_date)" + ], "attribute_identifier": "id", "attributes_searchable": ["name", "release_date"], - "attributes_displayed": ["name", "release_date"], - "attributes_ranked": ["release_date"] + "attributes_displayed": ["name", "release_date"] } "#; let settings: Settings = serde_json::from_str(data).unwrap(); diff --git a/meilisearch-core/src/settings.rs b/meilisearch-core/src/settings.rs index 0af1c83b4..3a1687060 100644 --- a/meilisearch-core/src/settings.rs +++ b/meilisearch-core/src/settings.rs @@ -18,7 +18,6 @@ pub struct Settings { pub attribute_identifier: Option, pub attributes_searchable: Option>, pub attributes_displayed: Option>, - pub attributes_ranked: Option>, pub stop_words: Option>, pub synonyms: Option>>, } @@ -60,7 +59,6 @@ impl Into for Settings { 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(), } @@ -130,6 +128,15 @@ impl ToString for RankingRule { } } +impl RankingRule { + pub fn get_field(&self) -> Option { + match self { + RankingRule::Asc(field) | RankingRule::Dsc(field) => Some((*field).clone()), + _ => None, + } + } +} + impl FromStr for RankingRule { type Err = RankingRuleConversionError; @@ -161,7 +168,6 @@ pub struct SettingsUpdate { pub attribute_identifier: UpdateState, pub attributes_searchable: UpdateState>, pub attributes_displayed: UpdateState>, - pub attributes_ranked: UpdateState>, pub stop_words: UpdateState>, pub synonyms: UpdateState>>, } @@ -174,7 +180,6 @@ impl Default for SettingsUpdate { attribute_identifier: UpdateState::Nothing, attributes_searchable: UpdateState::Nothing, attributes_displayed: UpdateState::Nothing, - attributes_ranked: UpdateState::Nothing, stop_words: UpdateState::Nothing, synonyms: UpdateState::Nothing, } diff --git a/meilisearch-core/src/update/settings_update.rs b/meilisearch-core/src/update/settings_update.rs index 087ac36ed..a67d7eedf 100644 --- a/meilisearch-core/src/update/settings_update.rs +++ b/meilisearch-core/src/update/settings_update.rs @@ -6,7 +6,7 @@ use sdset::SetBuf; use meilisearch_schema::Schema; use crate::database::{MainT, UpdateT}; -use crate::settings::{UpdateState, SettingsUpdate}; +use crate::settings::{UpdateState, SettingsUpdate, RankingRule}; use crate::update::documents_addition::reindex_all_documents; use crate::update::{next_update_id, Update}; use crate::{store, MResult, Error}; @@ -30,8 +30,6 @@ pub fn apply_settings_update( index: &store::Index, settings: SettingsUpdate, ) -> MResult<()> { - - let mut must_reindex = false; let mut schema = match index.main.schema(writer)? { @@ -46,9 +44,13 @@ pub fn apply_settings_update( match settings.ranking_rules { UpdateState::Update(v) => { + let ranked_field: Vec = v.iter().filter_map(RankingRule::get_field).collect(); + schema.update_ranked(ranked_field)?; index.main.put_ranking_rules(writer, v)?; }, UpdateState::Clear => { + let clear: Vec = Vec::new(); + schema.update_ranked(clear)?; index.main.delete_ranking_rules(writer)?; }, _ => (), @@ -99,25 +101,6 @@ pub fn apply_settings_update( } } }; - match settings.attributes_ranked.clone() { - UpdateState::Update(v) => schema.update_ranked(v)?, - UpdateState::Clear => { - let clear: Vec = Vec::new(); - schema.update_ranked(clear)?; - }, - UpdateState::Nothing => (), - UpdateState::Add(attrs) => { - for attr in attrs { - schema.set_ranked(attr)?; - } - }, - UpdateState::Delete(attrs) => { - for attr in attrs { - schema.remove_ranked(attr); - } - } - }; - match settings.attribute_identifier.clone() { UpdateState::Update(v) => { schema.set_identifier(v)?; diff --git a/meilisearch-http/src/routes/setting.rs b/meilisearch-http/src/routes/setting.rs index f428f635a..b5a25635d 100644 --- a/meilisearch-http/src/routes/setting.rs +++ b/meilisearch-http/src/routes/setting.rs @@ -60,7 +60,6 @@ pub async fn get_all(ctx: Request) -> SResult { let attribute_identifier = schema.clone().map(|s| s.identifier()); let attributes_searchable = schema.clone().map(|s| s.get_indexed_name()); let attributes_displayed = schema.clone().map(|s| s.get_displayed_name()); - let attributes_ranked = schema.map(|s| s.get_ranked_name()); let settings = Settings { ranking_rules, @@ -68,7 +67,6 @@ pub async fn get_all(ctx: Request) -> SResult { attribute_identifier, attributes_searchable, attributes_displayed, - attributes_ranked, stop_words, synonyms, }; @@ -102,7 +100,6 @@ pub async fn delete_all(ctx: Request) -> SResult { attribute_identifier: UpdateState::Clear, attributes_searchable: UpdateState::Clear, attributes_displayed: UpdateState::Clear, - attributes_ranked: UpdateState::Clear, stop_words: UpdateState::Clear, synonyms: UpdateState::Clear, }; @@ -310,7 +307,6 @@ pub struct AttributesSettings { pub attribute_identifier: Option, pub attributes_searchable: Option>, pub attributes_displayed: Option>, - pub attributes_ranked: Option>, } pub async fn get_attributes(ctx: Request) -> SResult { @@ -324,13 +320,11 @@ pub async fn get_attributes(ctx: Request) -> SResult { let attribute_identifier = schema.clone().map(|s| s.identifier()); let attributes_searchable = schema.clone().map(|s| s.get_indexed_name()); let attributes_displayed = schema.clone().map(|s| s.get_displayed_name()); - let attributes_ranked = schema.map(|s| s.get_ranked_name()); let settings = AttributesSettings { attribute_identifier, attributes_searchable, attributes_displayed, - attributes_ranked, }; Ok(tide::Response::new(200).body_json(&settings).unwrap()) @@ -347,7 +341,6 @@ pub async fn update_attributes(mut ctx: Request) -> SResult { attribute_identifier: settings.attribute_identifier, attributes_searchable: settings.attributes_searchable, attributes_displayed: settings.attributes_displayed, - attributes_ranked: settings.attributes_ranked, .. Settings::default() };