2020-10-26 17:57:34 +08:00
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
use crate::Index;
|
|
|
|
|
|
|
|
pub struct ClearDocuments<'t, 'u, 'i> {
|
2020-10-30 18:42:00 +08:00
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
2020-10-26 17:57:34 +08:00
|
|
|
index: &'i Index,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
|
2020-10-30 18:42:00 +08:00
|
|
|
pub fn new(wtxn: &'t mut heed::RwTxn<'i, 'u>, index: &'i Index) -> ClearDocuments<'t, 'u, 'i> {
|
2020-10-26 17:57:34 +08:00
|
|
|
ClearDocuments { wtxn, index }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn execute(self) -> anyhow::Result<usize> {
|
|
|
|
let Index {
|
2020-10-30 17:56:35 +08:00
|
|
|
env: _env,
|
2020-10-26 17:57:34 +08:00
|
|
|
main: _main,
|
|
|
|
word_docids,
|
|
|
|
docid_word_positions,
|
|
|
|
word_pair_proximity_docids,
|
2020-11-11 23:04:04 +08:00
|
|
|
facet_field_id_value_docids,
|
2020-10-26 17:57:34 +08:00
|
|
|
documents,
|
|
|
|
} = self.index;
|
|
|
|
|
2020-11-11 23:04:04 +08:00
|
|
|
// We retrieve the number of documents ids that we are deleting.
|
|
|
|
let number_of_documents = self.index.number_of_documents(self.wtxn)?;
|
2020-10-26 17:57:34 +08:00
|
|
|
|
2020-11-11 23:04:04 +08:00
|
|
|
// We clean some of the main engine datastructures.
|
|
|
|
self.index.put_words_fst(self.wtxn, &fst::Set::default())?;
|
2020-11-22 18:54:04 +08:00
|
|
|
self.index.put_external_documents_ids(self.wtxn, &fst::Map::default())?;
|
2020-10-26 17:57:34 +08:00
|
|
|
self.index.put_documents_ids(self.wtxn, &RoaringBitmap::default())?;
|
|
|
|
|
2020-11-11 23:04:04 +08:00
|
|
|
// Clear the other databases.
|
2020-10-26 17:57:34 +08:00
|
|
|
word_docids.clear(self.wtxn)?;
|
|
|
|
docid_word_positions.clear(self.wtxn)?;
|
|
|
|
word_pair_proximity_docids.clear(self.wtxn)?;
|
2020-11-11 23:04:04 +08:00
|
|
|
facet_field_id_value_docids.clear(self.wtxn)?;
|
2020-10-26 17:57:34 +08:00
|
|
|
documents.clear(self.wtxn)?;
|
|
|
|
|
2020-11-11 23:04:04 +08:00
|
|
|
Ok(number_of_documents)
|
2020-10-26 17:57:34 +08:00
|
|
|
}
|
|
|
|
}
|