fix update system

This commit is contained in:
qdequele 2020-01-22 14:29:39 +01:00
parent 58fe87067b
commit f77f38dfa0
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
6 changed files with 50 additions and 40 deletions

View File

@ -381,9 +381,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description"] "attributesDisplayed": ["name", "description"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -441,9 +441,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description"] "attributesDisplayed": ["name", "description"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -500,9 +500,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name"], "attributesSearchable": ["name"],
"attributes_displayed": ["name"] "attributesDisplayed": ["name"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -552,9 +552,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description"] "attributesDisplayed": ["name", "description"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -590,9 +590,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description", "age", "sex"], "attributesSearchable": ["name", "description", "age", "sex"],
"attributes_displayed": ["name", "description", "age", "sex"] "attributesDisplayed": ["name", "description", "age", "sex"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -657,9 +657,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description", "city", "age", "sex"], "attributesSearchable": ["name", "description", "city", "age", "sex"],
"attributes_displayed": ["name", "description", "city", "age", "sex"] "attributesDisplayed": ["name", "description", "city", "age", "sex"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -696,9 +696,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description"] "attributesDisplayed": ["name", "description"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -773,9 +773,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description", "id"] "attributesDisplayed": ["name", "description", "id"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -909,9 +909,9 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "description"], "attributesSearchable": ["name", "description"],
"attributes_displayed": ["name", "description"] "attributesDisplayed": ["name", "description"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();
@ -973,7 +973,7 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"ranking_rules": [ "rankingRules": [
"_typo", "_typo",
"_words", "_words",
"_proximity", "_proximity",
@ -982,9 +982,9 @@ mod tests {
"_exact", "_exact",
"dsc(release_date)" "dsc(release_date)"
], ],
"attribute_identifier": "id", "attributeIdentifier": "id",
"attributes_searchable": ["name", "release_date"], "attributesSearchable": ["name", "release_date"],
"attributes_displayed": ["name", "release_date"] "attributesDisplayed": ["name", "release_date"]
} }
"#; "#;
let settings: Settings = serde_json::from_str(data).unwrap(); let settings: Settings = serde_json::from_str(data).unwrap();

View File

@ -275,7 +275,7 @@ mod tests {
let mut final_indexes = Vec::new(); let mut final_indexes = Vec::new();
for index in indexes { for index in indexes {
let name = index.attribute.to_string(); let name = index.attribute.to_string();
schema.get_or_create(&name).unwrap(); schema.get_or_create_empty(&name).unwrap();
let indexed_pos = schema.set_indexed(&name).unwrap().1; let indexed_pos = schema.set_indexed(&name).unwrap().1;
let index = DocIndex { let index = DocIndex {
attribute: indexed_pos.0, attribute: indexed_pos.0,

View File

@ -305,7 +305,7 @@ pub fn serialize_value<'a, T: ?Sized>(
where where
T: ser::Serialize, T: ser::Serialize,
{ {
let field_id = schema.get_or_create(attribute)?; let field_id = schema.get_or_create_empty(attribute.clone())?;
serialize_value_with_id( serialize_value_with_id(
txn, txn,

View File

@ -222,8 +222,6 @@ impl Index {
let schema = self.main.schema(reader)?; let schema = self.main.schema(reader)?;
let schema = schema.ok_or(Error::SchemaMissing)?; let schema = schema.ok_or(Error::SchemaMissing)?;
// let attributes = attributes.map(|a| a.iter().filter_map(|name| schema.get_id(*name)).collect());
let attributes = match attributes { let attributes = match attributes {
Some(attributes) => Some(attributes.iter().filter_map(|name| schema.get_id(*name)).collect()), Some(attributes) => Some(attributes.iter().filter_map(|name| schema.get_id(*name)).collect()),
None => None, None => None,

View File

@ -47,11 +47,13 @@ pub fn apply_settings_update(
let ranked_field: Vec<String> = v.iter().filter_map(RankingRule::get_field).collect(); let ranked_field: Vec<String> = v.iter().filter_map(RankingRule::get_field).collect();
schema.update_ranked(ranked_field)?; schema.update_ranked(ranked_field)?;
index.main.put_ranking_rules(writer, v)?; index.main.put_ranking_rules(writer, v)?;
must_reindex = true;
}, },
UpdateState::Clear => { UpdateState::Clear => {
let clear: Vec<String> = Vec::new(); let clear: Vec<String> = Vec::new();
schema.update_ranked(clear)?; schema.update_ranked(clear)?;
index.main.delete_ranking_rules(writer)?; index.main.delete_ranking_rules(writer)?;
must_reindex = true;
}, },
_ => (), _ => (),
} }
@ -66,21 +68,27 @@ pub fn apply_settings_update(
} }
match settings.attributes_searchable.clone() { match settings.attributes_searchable.clone() {
UpdateState::Update(v) => schema.update_indexed(v)?, UpdateState::Update(v) => {
schema.update_indexed(v)?;
must_reindex = true;
},
UpdateState::Clear => { UpdateState::Clear => {
let clear: Vec<String> = Vec::new(); let clear: Vec<String> = Vec::new();
schema.update_indexed(clear)?; schema.update_indexed(clear)?;
must_reindex = true;
}, },
UpdateState::Nothing => (), UpdateState::Nothing => (),
UpdateState::Add(attrs) => { UpdateState::Add(attrs) => {
for attr in attrs { for attr in attrs {
schema.set_indexed(attr)?; schema.set_indexed(attr)?;
} }
must_reindex = true;
}, },
UpdateState::Delete(attrs) => { UpdateState::Delete(attrs) => {
for attr in attrs { for attr in attrs {
schema.remove_indexed(attr); schema.remove_indexed(attr);
} }
must_reindex = true;
} }
}; };
match settings.attributes_displayed.clone() { match settings.attributes_displayed.clone() {
@ -105,11 +113,10 @@ pub fn apply_settings_update(
UpdateState::Update(v) => { UpdateState::Update(v) => {
schema.set_identifier(v)?; schema.set_identifier(v)?;
index.main.put_schema(writer, &schema)?; index.main.put_schema(writer, &schema)?;
}, must_reindex = true;
UpdateState::Clear => {
index.main.delete_schema(writer)?;
}, },
_ => { _ => {
println!("schema: {:?}", schema);
index.main.put_schema(writer, &schema)?; index.main.put_schema(writer, &schema)?;
}, },
}; };
@ -150,6 +157,9 @@ pub fn apply_settings_update(
docs_words_store, docs_words_store,
)?; )?;
} }
if let UpdateState::Clear = settings.attribute_identifier {
index.main.delete_schema(writer)?;
}
Ok(()) Ok(())
} }

View File

@ -84,7 +84,9 @@ impl DataInner {
let mut fields_frequency = HashMap::<_, usize>::new(); let mut fields_frequency = HashMap::<_, usize>::new();
for result in all_documents_fields { for result in all_documents_fields {
let (_, attr, _) = result?; let (_, attr, _) = result?;
*fields_frequency.entry(schema.indexed_pos_to_field_id(attr).unwrap()).or_default() += 1; if let Some(field_id) = schema.indexed_pos_to_field_id(attr) {
*fields_frequency.entry(field_id).or_default() += 1;
}
} }
// convert attributes to their names // convert attributes to their names