1554: Fix dump v1 (attributesForFaceting, and criteria) r=curquiza a=MarinPostma

close #1553


Co-authored-by: mpostma <postma.marin@protonmail.com>
This commit is contained in:
bors[bot] 2021-08-05 19:45:52 +00:00 committed by GitHub
commit 7e3b2ddff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

2
Cargo.lock generated
View File

@ -1700,7 +1700,7 @@ dependencies = [
[[package]] [[package]]
name = "meilisearch-tokenizer" name = "meilisearch-tokenizer"
version = "0.2.3" version = "0.2.3"
source = "git+https://github.com/meilisearch/Tokenizer.git?tag=v0.2.3#c2399c3f879144ad92e20ae057e14984dfd22781" source = "git+https://github.com/meilisearch/tokenizer.git?tag=v0.2.3#c2399c3f879144ad92e20ae057e14984dfd22781"
dependencies = [ dependencies = [
"character_converter", "character_converter",
"cow-utils", "cow-utils",

View File

@ -73,7 +73,7 @@ struct Settings {
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>, pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
#[serde(default, deserialize_with = "deserialize_some")] #[serde(default, deserialize_with = "deserialize_some")]
pub filterable_attributes: Option<Option<Vec<String>>>, pub attributes_for_faceting: Option<Option<Vec<String>>>,
} }
fn load_index( fn load_index(
@ -142,23 +142,19 @@ impl From<Settings> for index_controller::Settings<Unchecked> {
// representing the name of the faceted field + the type of the field. Since the type // representing the name of the faceted field + the type of the field. Since the type
// was not known in the V1 of the dump we are just going to assume everything is a // was not known in the V1 of the dump we are just going to assume everything is a
// String // String
filterable_attributes: settings.filterable_attributes.map(|o| o.map(|vec| vec.into_iter().collect())), filterable_attributes: settings.attributes_for_faceting.map(|o| o.map(|vec| vec.into_iter().collect())),
// we need to convert the old `Vec<String>` into a `BTreeSet<String>` // we need to convert the old `Vec<String>` into a `BTreeSet<String>`
ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter_map(|criterion| { ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter(|criterion| {
match criterion.as_str() { match criterion.as_str() {
"words" | "typo" | "proximity" | "attribute" => Some(criterion), "words" | "typo" | "proximity" | "attribute" | "exactness" => true,
s if s.starts_with("asc") || s.starts_with("desc") => Some(criterion), s if s.starts_with("asc") || s.starts_with("desc") => true,
"wordsPosition" => { "wordsPosition" => {
warn!("The criteria `words` and `wordsPosition` have been merged into a single criterion `words` so `wordsPositon` will be ignored"); warn!("The criteria `attribute` and `wordsPosition` have been merged into a single criterion `attribute` so `wordsPositon` will be ignored");
Some(String::from("words")) false
}
"exactness" => {
error!("The criterion `{}` is not implemented currently and thus will be ignored", criterion);
None
} }
s => { s => {
error!("Unknown criterion found in the dump: `{}`, it will be ignored", s); error!("Unknown criterion found in the dump: `{}`, it will be ignored", s);
None false
} }
} }
}).collect())), }).collect())),
@ -180,3 +176,17 @@ fn import_settings(dir_path: impl AsRef<Path>) -> anyhow::Result<Settings> {
Ok(metadata) Ok(metadata)
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn settings_format_regression() {
let settings = Settings::default();
assert_eq!(
r##"{"rankingRules":null,"distinctAttribute":null,"searchableAttributes":null,"displayedAttributes":null,"stopWords":null,"synonyms":null,"attributesForFaceting":null}"##,
serde_json::to_string(&settings).unwrap()
);
}
}