set new attributes indexed if needed

This commit is contained in:
Quentin de Quelen 2020-01-27 08:52:36 +01:00 committed by qdequele
parent b1528f9466
commit 585bba43a0
No known key found for this signature in database
GPG key ID: B3F0A000EBF11745
10 changed files with 100 additions and 648 deletions

View file

@ -269,7 +269,7 @@ mod tests {
let mut postings_lists = HashMap::new();
let mut fields_counts = HashMap::<_, u16>::new();
let mut schema = Schema::default();
let mut schema = Schema::with_identifier("id");
for (word, indexes) in iter {
let mut final_indexes = Vec::new();

View file

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

View file

@ -21,6 +21,7 @@ pub struct Settings {
pub attributes_displayed: Option<HashSet<String>>,
pub stop_words: Option<BTreeSet<String>>,
pub synonyms: Option<BTreeMap<String, Vec<String>>>,
pub index_new_fields: Option<bool>,
}
impl Settings {
@ -40,6 +41,7 @@ impl Settings {
attributes_displayed: UpdateState::convert_with_default(settings.attributes_displayed, UpdateState::Clear),
stop_words: UpdateState::convert_with_default(settings.stop_words, UpdateState::Clear),
synonyms: UpdateState::convert_with_default(settings.synonyms, UpdateState::Clear),
index_new_fields: UpdateState::convert_with_default(settings.index_new_fields, UpdateState::Clear),
}
}
}
@ -61,6 +63,7 @@ impl Into<SettingsUpdate> for Settings {
attributes_displayed: settings.attributes_displayed.into(),
stop_words: settings.stop_words.into(),
synonyms: settings.synonyms.into(),
index_new_fields: settings.index_new_fields.into(),
}
}
}
@ -184,6 +187,7 @@ pub struct SettingsUpdate {
pub attributes_displayed: UpdateState<HashSet<String>>,
pub stop_words: UpdateState<BTreeSet<String>>,
pub synonyms: UpdateState<BTreeMap<String, Vec<String>>>,
pub index_new_fields: UpdateState<bool>,
}
impl Default for SettingsUpdate {
@ -196,6 +200,7 @@ impl Default for SettingsUpdate {
attributes_displayed: UpdateState::Nothing,
stop_words: UpdateState::Nothing,
synonyms: UpdateState::Nothing,
index_new_fields: UpdateState::Nothing,
}
}
}

View file

@ -57,6 +57,7 @@ pub fn apply_settings_update(
},
_ => (),
}
match settings.ranking_distinct {
UpdateState::Update(v) => {
index.main.put_ranking_distinct(writer, v)?;
@ -67,6 +68,16 @@ pub fn apply_settings_update(
_ => (),
}
match settings.index_new_fields {
UpdateState::Update(v) => {
schema.set_must_index_new_fields(v);
},
UpdateState::Clear => {
schema.set_must_index_new_fields(true);
},
_ => (),
}
match settings.attributes_searchable.clone() {
UpdateState::Update(v) => {
schema.update_indexed(v)?;
@ -109,6 +120,7 @@ pub fn apply_settings_update(
}
}
};
match settings.attribute_identifier.clone() {
UpdateState::Update(v) => {
schema.set_identifier(v)?;