implements the index deletion, creation and swap

This commit is contained in:
Tamo 2022-09-07 21:27:06 +02:00 committed by Clément Renault
parent fa27485070
commit b1f0431ab4
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
4 changed files with 70 additions and 7 deletions

View file

@ -22,6 +22,7 @@ use super::{Checked, Settings};
pub type Document = Map<String, Value>;
// @kero, what is this structure? Shouldn't it move entirely to milli?
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IndexMeta {
@ -50,6 +51,7 @@ impl IndexMeta {
}
}
// @kero Maybe this should be entirely generated somewhere else since it doesn't really concern the index?
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct IndexStats {
@ -105,6 +107,14 @@ impl Index {
self.inner.as_ref().clone().prepare_for_closing();
}
pub fn delete(self) -> Result<()> {
let path = self.path().to_path_buf();
self.inner.as_ref().clone().prepare_for_closing().wait();
std::fs::remove_file(path)?;
Ok(())
}
pub fn stats(&self) -> Result<IndexStats> {
let rtxn = self.read_txn()?;

View file

@ -137,6 +137,13 @@ pub mod test {
}
}
pub fn delete(self) -> Result<()> {
match self {
MockIndex::Real(index) => index.delete(),
MockIndex::Mock(m) => unsafe { m.get("delete").call(()) },
}
}
pub fn perform_search(&self, query: SearchQuery) -> Result<SearchResult> {
match self {
MockIndex::Real(index) => index.perform_search(query),