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

View File

@ -275,7 +275,7 @@ mod tests {
let mut final_indexes = Vec::new();
for index in indexes {
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 index = DocIndex {
attribute: indexed_pos.0,

View File

@ -305,7 +305,7 @@ pub fn serialize_value<'a, T: ?Sized>(
where
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(
txn,

View File

@ -222,8 +222,6 @@ impl Index {
let schema = self.main.schema(reader)?;
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 {
Some(attributes) => Some(attributes.iter().filter_map(|name| schema.get_id(*name)).collect()),
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();
schema.update_ranked(ranked_field)?;
index.main.put_ranking_rules(writer, v)?;
must_reindex = true;
},
UpdateState::Clear => {
let clear: Vec<String> = Vec::new();
schema.update_ranked(clear)?;
index.main.delete_ranking_rules(writer)?;
must_reindex = true;
},
_ => (),
}
@ -66,21 +68,27 @@ pub fn apply_settings_update(
}
match settings.attributes_searchable.clone() {
UpdateState::Update(v) => schema.update_indexed(v)?,
UpdateState::Update(v) => {
schema.update_indexed(v)?;
must_reindex = true;
},
UpdateState::Clear => {
let clear: Vec<String> = Vec::new();
schema.update_indexed(clear)?;
must_reindex = true;
},
UpdateState::Nothing => (),
UpdateState::Add(attrs) => {
for attr in attrs {
schema.set_indexed(attr)?;
}
must_reindex = true;
},
UpdateState::Delete(attrs) => {
for attr in attrs {
schema.remove_indexed(attr);
}
must_reindex = true;
}
};
match settings.attributes_displayed.clone() {
@ -105,11 +113,10 @@ pub fn apply_settings_update(
UpdateState::Update(v) => {
schema.set_identifier(v)?;
index.main.put_schema(writer, &schema)?;
},
UpdateState::Clear => {
index.main.delete_schema(writer)?;
must_reindex = true;
},
_ => {
println!("schema: {:?}", schema);
index.main.put_schema(writer, &schema)?;
},
};
@ -150,6 +157,9 @@ pub fn apply_settings_update(
docs_words_store,
)?;
}
if let UpdateState::Clear = settings.attribute_identifier {
index.main.delete_schema(writer)?;
}
Ok(())
}

View File

@ -84,7 +84,9 @@ impl DataInner {
let mut fields_frequency = HashMap::<_, usize>::new();
for result in all_documents_fields {
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