From 3e76dc718bb944781a347c8565099aebd85d4653 Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Tue, 17 Sep 2019 11:57:29 +0200 Subject: [PATCH] feat: delete an index and all it's associated data --- meilidb-data/src/database/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/meilidb-data/src/database/mod.rs b/meilidb-data/src/database/mod.rs index 27525c5c6..1975dd3e8 100644 --- a/meilidb-data/src/database/mod.rs +++ b/meilidb-data/src/database/mod.rs @@ -118,6 +118,26 @@ impl Database { Ok(index) } + pub fn delete_index(&self, name: &str) -> Result<(), Error> { + let mut cache = self.cache.write().unwrap(); + + self.inner.drop_cf(name)?; + let _ = self.inner.drop_cf(&format!("{}-synonyms", name)); + let _ = self.inner.drop_cf(&format!("{}-words", name)); + let _ = self.inner.drop_cf(&format!("{}-docs-words", name)); + let _ = self.inner.drop_cf(&format!("{}-documents", name)); + let _ = self.inner.drop_cf(&format!("{}-custom", name)); + let _ = self.inner.drop_cf(&format!("{}-updates", name)); + let _ = self.inner.drop_cf(&format!("{}-updates-results", name)); + cache.remove(name); + + if let Ok(mut index_list) = self.indexes() { + index_list.remove(name); + let _ = self.set_indexes(&index_list); + } + Ok(()) + } + pub fn common_index(&self) -> Arc { self.common.clone() }