Move the IndexDocuments update into its own module

This commit is contained in:
Clément Renault 2020-10-26 11:02:44 +01:00
parent 8f76ec97c0
commit 5c62fbb6a8
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 36 additions and 31 deletions

View File

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

View File

@ -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;

View File

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