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!() - } -}