2020-10-26 10:57:34 +01:00
|
|
|
use roaring::RoaringBitmap;
|
2020-11-22 17:53:33 +01:00
|
|
|
use crate::{ExternalDocumentsIds, Index};
|
2020-10-26 10:57:34 +01:00
|
|
|
|
|
|
|
pub struct ClearDocuments<'t, 'u, 'i> {
|
2020-10-30 11:42:00 +01:00
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
2020-10-26 10:57:34 +01:00
|
|
|
index: &'i Index,
|
2020-12-22 16:21:07 +01:00
|
|
|
_update_id: u64,
|
2020-10-26 10:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
|
2020-12-22 16:21:07 +01:00
|
|
|
pub fn new(
|
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
|
|
|
index: &'i Index,
|
|
|
|
update_id: u64
|
|
|
|
) -> ClearDocuments<'t, 'u, 'i> {
|
|
|
|
|
|
|
|
ClearDocuments { wtxn, index, _update_id: update_id }
|
2020-10-26 10:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn execute(self) -> anyhow::Result<usize> {
|
|
|
|
let Index {
|
2020-10-30 10:56:35 +01:00
|
|
|
env: _env,
|
2020-10-26 10:57:34 +01:00
|
|
|
main: _main,
|
|
|
|
word_docids,
|
2021-02-03 10:30:33 +01:00
|
|
|
word_prefix_docids,
|
2020-10-26 10:57:34 +01:00
|
|
|
docid_word_positions,
|
|
|
|
word_pair_proximity_docids,
|
2020-11-11 16:04:04 +01:00
|
|
|
facet_field_id_value_docids,
|
2020-12-02 18:31:41 +01:00
|
|
|
field_id_docid_facet_values,
|
2020-10-26 10:57:34 +01:00
|
|
|
documents,
|
|
|
|
} = self.index;
|
|
|
|
|
2020-11-11 16:04:04 +01:00
|
|
|
// We retrieve the number of documents ids that we are deleting.
|
|
|
|
let number_of_documents = self.index.number_of_documents(self.wtxn)?;
|
2021-01-20 17:27:43 +01:00
|
|
|
let faceted_fields = self.index.faceted_fields_ids(self.wtxn)?;
|
2020-10-26 10:57:34 +01:00
|
|
|
|
2020-11-11 16:04:04 +01:00
|
|
|
// We clean some of the main engine datastructures.
|
|
|
|
self.index.put_words_fst(self.wtxn, &fst::Set::default())?;
|
2020-11-22 17:53:33 +01:00
|
|
|
self.index.put_external_documents_ids(self.wtxn, &ExternalDocumentsIds::default())?;
|
2020-10-26 10:57:34 +01:00
|
|
|
self.index.put_documents_ids(self.wtxn, &RoaringBitmap::default())?;
|
|
|
|
|
2020-11-23 13:08:57 +01:00
|
|
|
// We clean all the faceted documents ids.
|
|
|
|
for (field_id, _) in faceted_fields {
|
|
|
|
self.index.put_faceted_documents_ids(self.wtxn, field_id, &RoaringBitmap::default())?;
|
|
|
|
}
|
|
|
|
|
2020-11-11 16:04:04 +01:00
|
|
|
// Clear the other databases.
|
2020-10-26 10:57:34 +01:00
|
|
|
word_docids.clear(self.wtxn)?;
|
|
|
|
docid_word_positions.clear(self.wtxn)?;
|
|
|
|
word_pair_proximity_docids.clear(self.wtxn)?;
|
2020-11-11 16:04:04 +01:00
|
|
|
facet_field_id_value_docids.clear(self.wtxn)?;
|
2020-12-02 18:31:41 +01:00
|
|
|
field_id_docid_facet_values.clear(self.wtxn)?;
|
2020-10-26 10:57:34 +01:00
|
|
|
documents.clear(self.wtxn)?;
|
|
|
|
|
2020-11-11 16:04:04 +01:00
|
|
|
Ok(number_of_documents)
|
2020-10-26 10:57:34 +01:00
|
|
|
}
|
|
|
|
}
|