From 5174c78f873dddca15f97bad3a7b91dc127159c5 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 29 Sep 2022 14:31:01 +0200 Subject: [PATCH] Implement the DocumentClear batch operation --- index-scheduler/src/batch.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index 46e3200ee..031289fc5 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -43,6 +43,7 @@ pub(crate) enum Batch { index_uid: String, cleared_tasks: Vec, + // TODO what's that boolean, does it mean that it removes things or what? settings: Vec<(bool, Settings)>, settings_tasks: Vec, }, @@ -53,6 +54,7 @@ pub(crate) enum Batch { content_files: Vec, document_addition_tasks: Vec, + // TODO what's that boolean, does it mean that it removes things or what? settings: Vec<(bool, Settings)>, settings_tasks: Vec, }, @@ -63,6 +65,7 @@ pub(crate) enum Batch { content_files: Vec, document_update_tasks: Vec, + // TODO what's that boolean, does it mean that it removes things or what? settings: Vec<(bool, Settings)>, settings_tasks: Vec, }, @@ -429,7 +432,27 @@ impl IndexScheduler { Batch::Cancel(_) => todo!(), Batch::Snapshot(_) => todo!(), Batch::Dump(_) => todo!(), - Batch::DocumentClear { tasks, .. } => todo!(), + Batch::DocumentClear { + index_uid, + mut tasks, + } => { + let rtxn = self.env.read_txn()?; + let index = self.index_mapper.index(&rtxn, &index_uid)?; + rtxn.abort()?; + + let ret = index.clear_documents(); + for task in &mut tasks { + task.details = Some(Details::ClearAll { + // TODO where can I find this information of how many documents did we delete? + deleted_documents: None, + }); + if let Err(ref error) = ret { + task.error = Some(error.into()); + } + } + + Ok(tasks) + } // TODO we should merge both document import with a method field Batch::DocumentAddition { index_uid,