add the possibility to totally clear the schema

This commit is contained in:
Quentin de Quelen 2020-01-18 19:30:25 +01:00 committed by qdequele
parent d280848ff6
commit 036977bfe4
No known key found for this signature in database
GPG key ID: B3F0A000EBF11745
3 changed files with 52 additions and 15 deletions

View file

@ -96,23 +96,23 @@ impl Main {
}
pub fn put_schema(self, writer: &mut heed::RwTxn<MainT>, schema: &Schema) -> ZResult<()> {
self.main
.put::<_, Str, SerdeBincode<Schema>>(writer, SCHEMA_KEY, schema)
self.main.put::<_, Str, SerdeBincode<Schema>>(writer, SCHEMA_KEY, schema)
}
pub fn schema(self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<Schema>> {
self.main
.get::<_, Str, SerdeBincode<Schema>>(reader, SCHEMA_KEY)
self.main.get::<_, Str, SerdeBincode<Schema>>(reader, SCHEMA_KEY)
}
pub fn delete_schema(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
self.main.delete::<_, Str>(writer, SCHEMA_KEY)
}
pub fn put_ranked_map(self, writer: &mut heed::RwTxn<MainT>, ranked_map: &RankedMap) -> ZResult<()> {
self.main
.put::<_, Str, SerdeBincode<RankedMap>>(writer, RANKED_MAP_KEY, &ranked_map)
self.main.put::<_, Str, SerdeBincode<RankedMap>>(writer, RANKED_MAP_KEY, &ranked_map)
}
pub fn ranked_map(self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<RankedMap>> {
self.main
.get::<_, Str, SerdeBincode<RankedMap>>(reader, RANKED_MAP_KEY)
self.main.get::<_, Str, SerdeBincode<RankedMap>>(reader, RANKED_MAP_KEY)
}
pub fn put_synonyms_fst(self, writer: &mut heed::RwTxn<MainT>, fst: &fst::Set) -> ZResult<()> {

View file

@ -63,10 +63,6 @@ pub fn apply_settings_update(
_ => (),
}
if let UpdateState::Update(id) = settings.attribute_identifier {
schema.set_identifier(id)?;
};
match settings.attributes_searchable.clone() {
UpdateState::Update(v) => schema.update_indexed(v)?,
UpdateState::Clear => {
@ -122,7 +118,18 @@ pub fn apply_settings_update(
}
};
index.main.put_schema(writer, &schema)?;
match settings.attribute_identifier.clone() {
UpdateState::Update(v) => {
schema.set_identifier(v)?;
index.main.put_schema(writer, &schema)?;
},
UpdateState::Clear => {
index.main.delete_schema(writer)?;
},
_ => {
index.main.put_schema(writer, &schema)?;
},
};
match settings.stop_words {
UpdateState::Update(stop_words) => {