From 5c62fbb6a8552cf4c48711fd684906d9f3c3f729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 26 Oct 2020 11:02:44 +0100 Subject: [PATCH] Move the IndexDocuments update into its own module --- src/update/index_documents/mod.rs | 33 +++++++++++++++++++++++++++++++ src/update/mod.rs | 2 ++ src/update/update_builder.rs | 32 +----------------------------- 3 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 src/update/index_documents/mod.rs diff --git a/src/update/index_documents/mod.rs b/src/update/index_documents/mod.rs new file mode 100644 index 000000000..0cdd68df1 --- /dev/null +++ b/src/update/index_documents/mod.rs @@ -0,0 +1,33 @@ +use crate::Index; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum IndexDocumentsMethod { + /// Replace the previous document with the new one, + /// removing all the already known attributes. + ReplaceDocuments, + + /// Merge the previous version of the document with the new version, + /// replacing old attributes values with the new ones and add the new attributes. + UpdateDocuments, +} + +pub struct IndexDocuments<'t, 'u, 'i> { + wtxn: &'t mut heed::RwTxn<'u>, + index: &'i Index, + update_method: IndexDocumentsMethod, +} + +impl<'t, 'u, 'i> IndexDocuments<'t, 'u, 'i> { + pub fn new(wtxn: &'t mut heed::RwTxn<'u>, index: &'i Index) -> IndexDocuments<'t, 'u, 'i> { + IndexDocuments { wtxn, index, update_method: IndexDocumentsMethod::ReplaceDocuments } + } + + pub fn index_documents_method(&mut self, method: IndexDocumentsMethod) -> &mut Self { + self.update_method = method; + self + } + + pub fn execute(self) -> anyhow::Result<()> { + todo!() + } +} diff --git a/src/update/mod.rs b/src/update/mod.rs index 31d4a8242..fcaffe9c0 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -1,11 +1,13 @@ mod available_documents_ids; mod clear_documents; mod delete_documents; +mod index_documents; mod update_builder; mod update_store; pub use self::available_documents_ids::AvailableDocumentsIds; pub use self::clear_documents::ClearDocuments; pub use self::delete_documents::DeleteDocuments; +pub use self::index_documents::{IndexDocuments, IndexDocumentsMethod}; pub use self::update_builder::UpdateBuilder; pub use self::update_store::UpdateStore; diff --git a/src/update/update_builder.rs b/src/update/update_builder.rs index b8b50c092..bbbc23619 100644 --- a/src/update/update_builder.rs +++ b/src/update/update_builder.rs @@ -9,6 +9,7 @@ use roaring::RoaringBitmap; use crate::{Index, BEU32}; use super::clear_documents::ClearDocuments; use super::delete_documents::DeleteDocuments; +use super::index_documents::IndexDocuments; pub struct UpdateBuilder { log_every_n: usize, @@ -99,34 +100,3 @@ impl UpdateBuilder { IndexDocuments::new(wtxn, index) } } - -pub enum IndexDocumentsMethod { - /// Replace the previous document with the new one, - /// removing all the already known attributes. - ReplaceDocuments, - - /// Merge the previous version of the document with the new version, - /// replacing old attributes values with the new ones and add the new attributes. - UpdateDocuments, -} - -pub struct IndexDocuments<'t, 'u, 'i> { - wtxn: &'t mut heed::RwTxn<'u>, - index: &'i Index, - update_method: IndexDocumentsMethod, -} - -impl<'t, 'u, 'i> IndexDocuments<'t, 'u, 'i> { - fn new(wtxn: &'t mut heed::RwTxn<'u>, index: &'i Index) -> IndexDocuments<'t, 'u, 'i> { - IndexDocuments { wtxn, index, update_method: IndexDocumentsMethod::ReplaceDocuments } - } - - pub fn index_documents_method(&mut self, method: IndexDocumentsMethod) -> &mut Self { - self.update_method = method; - self - } - - pub fn execute(self) -> anyhow::Result<()> { - todo!() - } -}