meilisearch/milli/src/update/new/indexer/document_deletion.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

use std::sync::Arc;
use rayon::iter::{ParallelBridge, ParallelIterator};
use roaring::RoaringBitmap;
2024-09-02 15:10:21 +02:00
use super::DocumentChanges;
use crate::update::new::{Deletion, DocumentChange, ItemsPool};
2024-09-12 18:01:02 +02:00
use crate::{FieldsIdsMap, Index, Result};
2024-09-02 14:42:27 +02:00
pub struct DocumentDeletion {
pub to_delete: RoaringBitmap,
}
2024-09-02 14:42:27 +02:00
impl DocumentDeletion {
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;
fn document_changes(
self,
_fields_ids_map: &mut FieldsIdsMap,
param: Self::Parameter,
) -> Result<impl ParallelIterator<Item = Result<DocumentChange>> + Clone + 'p> {
2024-09-12 18:01:02 +02:00
let index = param;
let items = Arc::new(ItemsPool::new(|| index.read_txn().map_err(crate::Error::from)));
Ok(self.to_delete.into_iter().par_bridge().map_with(items, |items, docid| {
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())))
})
}))
}
}