mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-27 07:14:26 +01:00
Move the ClearDocuments update into its own module
This commit is contained in:
parent
1e1821f002
commit
92ef1faa97
49
src/update/clear_documents.rs
Normal file
49
src/update/clear_documents.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use roaring::RoaringBitmap;
|
||||||
|
use crate::Index;
|
||||||
|
|
||||||
|
pub struct ClearDocuments<'t, 'u, 'i> {
|
||||||
|
wtxn: &'t mut heed::RwTxn<'u>,
|
||||||
|
index: &'i Index,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
|
||||||
|
pub fn new(wtxn: &'t mut heed::RwTxn<'u>, index: &'i Index) -> ClearDocuments<'t, 'u, 'i> {
|
||||||
|
ClearDocuments { wtxn, index }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute(self) -> anyhow::Result<usize> {
|
||||||
|
let Index {
|
||||||
|
main: _main,
|
||||||
|
word_docids,
|
||||||
|
docid_word_positions,
|
||||||
|
word_pair_proximity_docids,
|
||||||
|
documents,
|
||||||
|
} = self.index;
|
||||||
|
|
||||||
|
// We clear the word fst.
|
||||||
|
self.index.put_words_fst(self.wtxn, &fst::Set::default())?;
|
||||||
|
|
||||||
|
// We clear the users ids documents ids.
|
||||||
|
self.index.put_users_ids_documents_ids(self.wtxn, &fst::Map::default())?;
|
||||||
|
|
||||||
|
// We retrieve the documents ids.
|
||||||
|
let documents_ids = self.index.documents_ids(self.wtxn)?;
|
||||||
|
|
||||||
|
// We clear the internal documents ids.
|
||||||
|
self.index.put_documents_ids(self.wtxn, &RoaringBitmap::default())?;
|
||||||
|
|
||||||
|
// We clear the word docids.
|
||||||
|
word_docids.clear(self.wtxn)?;
|
||||||
|
|
||||||
|
// We clear the docid word positions.
|
||||||
|
docid_word_positions.clear(self.wtxn)?;
|
||||||
|
|
||||||
|
// We clear the word pair proximity docids.
|
||||||
|
word_pair_proximity_docids.clear(self.wtxn)?;
|
||||||
|
|
||||||
|
// We clear the documents themselves.
|
||||||
|
documents.clear(self.wtxn)?;
|
||||||
|
|
||||||
|
Ok(documents_ids.len() as usize)
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,9 @@
|
|||||||
mod available_documents_ids;
|
mod available_documents_ids;
|
||||||
|
mod clear_documents;
|
||||||
mod update_builder;
|
mod update_builder;
|
||||||
mod update_store;
|
mod update_store;
|
||||||
|
|
||||||
pub use self::available_documents_ids::AvailableDocumentsIds;
|
pub use self::available_documents_ids::AvailableDocumentsIds;
|
||||||
|
pub use self::clear_documents::ClearDocuments;
|
||||||
pub use self::update_builder::UpdateBuilder;
|
pub use self::update_builder::UpdateBuilder;
|
||||||
pub use self::update_store::UpdateStore;
|
pub use self::update_store::UpdateStore;
|
||||||
|
@ -7,6 +7,7 @@ use itertools::Itertools;
|
|||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
|
|
||||||
use crate::{Index, BEU32};
|
use crate::{Index, BEU32};
|
||||||
|
use super::clear_documents::ClearDocuments;
|
||||||
|
|
||||||
pub struct UpdateBuilder {
|
pub struct UpdateBuilder {
|
||||||
log_every_n: usize,
|
log_every_n: usize,
|
||||||
@ -98,53 +99,6 @@ impl UpdateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ClearDocuments<'t, 'u, 'i> {
|
|
||||||
wtxn: &'t mut heed::RwTxn<'u>,
|
|
||||||
index: &'i Index,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
|
|
||||||
fn new(wtxn: &'t mut heed::RwTxn<'u>, index: &'i Index) -> ClearDocuments<'t, 'u, 'i> {
|
|
||||||
ClearDocuments { wtxn, index }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn execute(self) -> anyhow::Result<usize> {
|
|
||||||
let Index {
|
|
||||||
main: _main,
|
|
||||||
word_docids,
|
|
||||||
docid_word_positions,
|
|
||||||
word_pair_proximity_docids,
|
|
||||||
documents,
|
|
||||||
} = self.index;
|
|
||||||
|
|
||||||
// We clear the word fst.
|
|
||||||
self.index.put_words_fst(self.wtxn, &fst::Set::default())?;
|
|
||||||
|
|
||||||
// We clear the users ids documents ids.
|
|
||||||
self.index.put_users_ids_documents_ids(self.wtxn, &fst::Map::default())?;
|
|
||||||
|
|
||||||
// We retrieve the documents ids.
|
|
||||||
let documents_ids = self.index.documents_ids(self.wtxn)?;
|
|
||||||
|
|
||||||
// We clear the internal documents ids.
|
|
||||||
self.index.put_documents_ids(self.wtxn, &RoaringBitmap::default())?;
|
|
||||||
|
|
||||||
// We clear the word docids.
|
|
||||||
word_docids.clear(self.wtxn)?;
|
|
||||||
|
|
||||||
// We clear the docid word positions.
|
|
||||||
docid_word_positions.clear(self.wtxn)?;
|
|
||||||
|
|
||||||
// We clear the word pair proximity docids.
|
|
||||||
word_pair_proximity_docids.clear(self.wtxn)?;
|
|
||||||
|
|
||||||
// We clear the documents themselves.
|
|
||||||
documents.clear(self.wtxn)?;
|
|
||||||
|
|
||||||
Ok(documents_ids.len() as usize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DeleteDocuments<'t, 'u, 'i> {
|
pub struct DeleteDocuments<'t, 'u, 'i> {
|
||||||
wtxn: &'t mut heed::RwTxn<'u>,
|
wtxn: &'t mut heed::RwTxn<'u>,
|
||||||
index: &'i Index,
|
index: &'i Index,
|
||||||
|
Loading…
Reference in New Issue
Block a user