2024-09-02 10:42:19 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-09-24 17:24:50 +02:00
|
|
|
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
|
2024-09-02 10:42:19 +02:00
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
|
2024-09-02 15:10:21 +02:00
|
|
|
use super::DocumentChanges;
|
2024-09-02 10:42:19 +02:00
|
|
|
use crate::update::new::{Deletion, DocumentChange, ItemsPool};
|
2024-09-12 18:01:02 +02:00
|
|
|
use crate::{FieldsIdsMap, Index, Result};
|
2024-09-02 10:42:19 +02:00
|
|
|
|
2024-09-02 14:42:27 +02:00
|
|
|
pub struct DocumentDeletion {
|
2024-09-02 10:42:19 +02:00
|
|
|
pub to_delete: RoaringBitmap,
|
|
|
|
}
|
|
|
|
|
2024-09-02 14:42:27 +02:00
|
|
|
impl DocumentDeletion {
|
2024-09-02 10:42:19 +02:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Self { to_delete: Default::default() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn delete_documents_by_docids(&mut self, docids: RoaringBitmap) {
|
|
|
|
self.to_delete |= docids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-02 15:10:21 +02:00
|
|
|
impl<'p> DocumentChanges<'p> for DocumentDeletion {
|
2024-09-12 18:01:02 +02:00
|
|
|
type Parameter = &'p Index;
|
2024-09-02 10:42:19 +02:00
|
|
|
|
|
|
|
fn document_changes(
|
|
|
|
self,
|
2024-09-03 12:01:01 +02:00
|
|
|
_fields_ids_map: &mut FieldsIdsMap,
|
2024-09-02 10:42:19 +02:00
|
|
|
param: Self::Parameter,
|
2024-09-24 17:24:50 +02:00
|
|
|
) -> Result<impl IndexedParallelIterator<Item = Result<DocumentChange>> + Clone + 'p> {
|
2024-09-12 18:01:02 +02:00
|
|
|
let index = param;
|
2024-09-02 10:42:19 +02:00
|
|
|
let items = Arc::new(ItemsPool::new(|| index.read_txn().map_err(crate::Error::from)));
|
2024-09-24 17:24:50 +02:00
|
|
|
let to_delete: Vec<_> = self.to_delete.into_iter().collect();
|
|
|
|
Ok(to_delete.into_par_iter().map_with(items, |items, docid| {
|
2024-09-02 10:42:19 +02:00
|
|
|
items.with(|rtxn| {
|
|
|
|
let current = index.document(rtxn, docid)?;
|
2024-09-12 18:01:02 +02:00
|
|
|
Ok(DocumentChange::Deletion(Deletion::create(docid, current.boxed())))
|
2024-09-02 10:42:19 +02:00
|
|
|
})
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|