mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
definitely remove attributes_ranked on settings; auto create it with ranking_rules
This commit is contained in:
parent
036977bfe4
commit
6deb481589
@ -973,10 +973,18 @@ mod tests {
|
|||||||
let settings = {
|
let settings = {
|
||||||
let data = r#"
|
let data = r#"
|
||||||
{
|
{
|
||||||
|
"ranking_rules": [
|
||||||
|
"_typo",
|
||||||
|
"_words",
|
||||||
|
"_proximity",
|
||||||
|
"_attribute",
|
||||||
|
"_words_position",
|
||||||
|
"_exact",
|
||||||
|
"dsc(release_date)"
|
||||||
|
],
|
||||||
"attribute_identifier": "id",
|
"attribute_identifier": "id",
|
||||||
"attributes_searchable": ["name", "release_date"],
|
"attributes_searchable": ["name", "release_date"],
|
||||||
"attributes_displayed": ["name", "release_date"],
|
"attributes_displayed": ["name", "release_date"]
|
||||||
"attributes_ranked": ["release_date"]
|
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let settings: Settings = serde_json::from_str(data).unwrap();
|
let settings: Settings = serde_json::from_str(data).unwrap();
|
||||||
|
@ -18,7 +18,6 @@ pub struct Settings {
|
|||||||
pub attribute_identifier: Option<String>,
|
pub attribute_identifier: Option<String>,
|
||||||
pub attributes_searchable: Option<Vec<String>>,
|
pub attributes_searchable: Option<Vec<String>>,
|
||||||
pub attributes_displayed: Option<HashSet<String>>,
|
pub attributes_displayed: Option<HashSet<String>>,
|
||||||
pub attributes_ranked: Option<HashSet<String>>,
|
|
||||||
pub stop_words: Option<BTreeSet<String>>,
|
pub stop_words: Option<BTreeSet<String>>,
|
||||||
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
|
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
|
||||||
}
|
}
|
||||||
@ -60,7 +59,6 @@ impl Into<SettingsUpdate> for Settings {
|
|||||||
attribute_identifier: settings.attribute_identifier.into(),
|
attribute_identifier: settings.attribute_identifier.into(),
|
||||||
attributes_searchable: settings.attributes_searchable.into(),
|
attributes_searchable: settings.attributes_searchable.into(),
|
||||||
attributes_displayed: settings.attributes_displayed.into(),
|
attributes_displayed: settings.attributes_displayed.into(),
|
||||||
attributes_ranked: settings.attributes_ranked.into(),
|
|
||||||
stop_words: settings.stop_words.into(),
|
stop_words: settings.stop_words.into(),
|
||||||
synonyms: settings.synonyms.into(),
|
synonyms: settings.synonyms.into(),
|
||||||
}
|
}
|
||||||
@ -130,6 +128,15 @@ impl ToString for RankingRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RankingRule {
|
||||||
|
pub fn get_field(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
RankingRule::Asc(field) | RankingRule::Dsc(field) => Some((*field).clone()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for RankingRule {
|
impl FromStr for RankingRule {
|
||||||
type Err = RankingRuleConversionError;
|
type Err = RankingRuleConversionError;
|
||||||
|
|
||||||
@ -161,7 +168,6 @@ pub struct SettingsUpdate {
|
|||||||
pub attribute_identifier: UpdateState<String>,
|
pub attribute_identifier: UpdateState<String>,
|
||||||
pub attributes_searchable: UpdateState<Vec<String>>,
|
pub attributes_searchable: UpdateState<Vec<String>>,
|
||||||
pub attributes_displayed: UpdateState<HashSet<String>>,
|
pub attributes_displayed: UpdateState<HashSet<String>>,
|
||||||
pub attributes_ranked: UpdateState<HashSet<String>>,
|
|
||||||
pub stop_words: UpdateState<BTreeSet<String>>,
|
pub stop_words: UpdateState<BTreeSet<String>>,
|
||||||
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
|
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
|
||||||
}
|
}
|
||||||
@ -174,7 +180,6 @@ impl Default for SettingsUpdate {
|
|||||||
attribute_identifier: UpdateState::Nothing,
|
attribute_identifier: UpdateState::Nothing,
|
||||||
attributes_searchable: UpdateState::Nothing,
|
attributes_searchable: UpdateState::Nothing,
|
||||||
attributes_displayed: UpdateState::Nothing,
|
attributes_displayed: UpdateState::Nothing,
|
||||||
attributes_ranked: UpdateState::Nothing,
|
|
||||||
stop_words: UpdateState::Nothing,
|
stop_words: UpdateState::Nothing,
|
||||||
synonyms: UpdateState::Nothing,
|
synonyms: UpdateState::Nothing,
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use sdset::SetBuf;
|
|||||||
use meilisearch_schema::Schema;
|
use meilisearch_schema::Schema;
|
||||||
|
|
||||||
use crate::database::{MainT, UpdateT};
|
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::documents_addition::reindex_all_documents;
|
||||||
use crate::update::{next_update_id, Update};
|
use crate::update::{next_update_id, Update};
|
||||||
use crate::{store, MResult, Error};
|
use crate::{store, MResult, Error};
|
||||||
@ -30,8 +30,6 @@ pub fn apply_settings_update(
|
|||||||
index: &store::Index,
|
index: &store::Index,
|
||||||
settings: SettingsUpdate,
|
settings: SettingsUpdate,
|
||||||
) -> MResult<()> {
|
) -> MResult<()> {
|
||||||
|
|
||||||
|
|
||||||
let mut must_reindex = false;
|
let mut must_reindex = false;
|
||||||
|
|
||||||
let mut schema = match index.main.schema(writer)? {
|
let mut schema = match index.main.schema(writer)? {
|
||||||
@ -46,9 +44,13 @@ pub fn apply_settings_update(
|
|||||||
|
|
||||||
match settings.ranking_rules {
|
match settings.ranking_rules {
|
||||||
UpdateState::Update(v) => {
|
UpdateState::Update(v) => {
|
||||||
|
let ranked_field: Vec<String> = v.iter().filter_map(RankingRule::get_field).collect();
|
||||||
|
schema.update_ranked(ranked_field)?;
|
||||||
index.main.put_ranking_rules(writer, v)?;
|
index.main.put_ranking_rules(writer, v)?;
|
||||||
},
|
},
|
||||||
UpdateState::Clear => {
|
UpdateState::Clear => {
|
||||||
|
let clear: Vec<String> = Vec::new();
|
||||||
|
schema.update_ranked(clear)?;
|
||||||
index.main.delete_ranking_rules(writer)?;
|
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<String> = 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() {
|
match settings.attribute_identifier.clone() {
|
||||||
UpdateState::Update(v) => {
|
UpdateState::Update(v) => {
|
||||||
schema.set_identifier(v)?;
|
schema.set_identifier(v)?;
|
||||||
|
@ -60,7 +60,6 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
||||||
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
||||||
let attributes_displayed = schema.clone().map(|s| s.get_displayed_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 {
|
let settings = Settings {
|
||||||
ranking_rules,
|
ranking_rules,
|
||||||
@ -68,7 +67,6 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
attribute_identifier,
|
attribute_identifier,
|
||||||
attributes_searchable,
|
attributes_searchable,
|
||||||
attributes_displayed,
|
attributes_displayed,
|
||||||
attributes_ranked,
|
|
||||||
stop_words,
|
stop_words,
|
||||||
synonyms,
|
synonyms,
|
||||||
};
|
};
|
||||||
@ -102,7 +100,6 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
attribute_identifier: UpdateState::Clear,
|
attribute_identifier: UpdateState::Clear,
|
||||||
attributes_searchable: UpdateState::Clear,
|
attributes_searchable: UpdateState::Clear,
|
||||||
attributes_displayed: UpdateState::Clear,
|
attributes_displayed: UpdateState::Clear,
|
||||||
attributes_ranked: UpdateState::Clear,
|
|
||||||
stop_words: UpdateState::Clear,
|
stop_words: UpdateState::Clear,
|
||||||
synonyms: UpdateState::Clear,
|
synonyms: UpdateState::Clear,
|
||||||
};
|
};
|
||||||
@ -310,7 +307,6 @@ pub struct AttributesSettings {
|
|||||||
pub attribute_identifier: Option<String>,
|
pub attribute_identifier: Option<String>,
|
||||||
pub attributes_searchable: Option<Vec<String>>,
|
pub attributes_searchable: Option<Vec<String>>,
|
||||||
pub attributes_displayed: Option<HashSet<String>>,
|
pub attributes_displayed: Option<HashSet<String>>,
|
||||||
pub attributes_ranked: Option<HashSet<String>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
|
pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
|
||||||
@ -324,13 +320,11 @@ pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
let attribute_identifier = schema.clone().map(|s| s.identifier());
|
||||||
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
let attributes_searchable = schema.clone().map(|s| s.get_indexed_name());
|
||||||
let attributes_displayed = schema.clone().map(|s| s.get_displayed_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 {
|
let settings = AttributesSettings {
|
||||||
attribute_identifier,
|
attribute_identifier,
|
||||||
attributes_searchable,
|
attributes_searchable,
|
||||||
attributes_displayed,
|
attributes_displayed,
|
||||||
attributes_ranked,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
Ok(tide::Response::new(200).body_json(&settings).unwrap())
|
||||||
@ -347,7 +341,6 @@ pub async fn update_attributes(mut ctx: Request<Data>) -> SResult<Response> {
|
|||||||
attribute_identifier: settings.attribute_identifier,
|
attribute_identifier: settings.attribute_identifier,
|
||||||
attributes_searchable: settings.attributes_searchable,
|
attributes_searchable: settings.attributes_searchable,
|
||||||
attributes_displayed: settings.attributes_displayed,
|
attributes_displayed: settings.attributes_displayed,
|
||||||
attributes_ranked: settings.attributes_ranked,
|
|
||||||
.. Settings::default()
|
.. Settings::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user