mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
feat: Introduce the DocumentsDeletion type
This commit is contained in:
parent
725e7b4229
commit
2a69170f14
@ -13,6 +13,7 @@ use meilidb_core::shared_data_cursor::{FromSharedDataCursor, SharedDataCursor};
|
|||||||
use meilidb_core::write_to_bytes::WriteToBytes;
|
use meilidb_core::write_to_bytes::WriteToBytes;
|
||||||
use meilidb_core::{DocumentId, Index as WordIndex};
|
use meilidb_core::{DocumentId, Index as WordIndex};
|
||||||
use rmp_serde::decode::{Error as RmpError};
|
use rmp_serde::decode::{Error as RmpError};
|
||||||
|
use sdset::SetBuf;
|
||||||
use serde::de;
|
use serde::de;
|
||||||
use sled::IVec;
|
use sled::IVec;
|
||||||
|
|
||||||
@ -222,8 +223,12 @@ impl RawIndex {
|
|||||||
self.ranked_map.lease()
|
self.ranked_map.lease()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_word_index(&self, word_index: Arc<WordIndex>) {
|
pub fn update_word_index(&self, word_index: Arc<WordIndex>) -> sled::Result<()> {
|
||||||
self.word_index.store(word_index)
|
let data = word_index.into_bytes();
|
||||||
|
self.inner.set("word-index", data).map(drop)?;
|
||||||
|
self.word_index.store(word_index);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_ranked_map(&self, ranked_map: Arc<RankedMap>) {
|
pub fn update_ranked_map(&self, ranked_map: Arc<RankedMap>) {
|
||||||
@ -316,6 +321,16 @@ impl Index {
|
|||||||
self.0.ranked_map()
|
self.0.ranked_map()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn documents_addition(&self) -> DocumentsAddition {
|
||||||
|
let index = self.0.clone();
|
||||||
|
DocumentsAddition::from_raw(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn documents_deletion(&self) -> DocumentsDeletion {
|
||||||
|
let index = self.0.clone();
|
||||||
|
DocumentsDeletion::from_raw(index)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn document<T>(
|
pub fn document<T>(
|
||||||
&self,
|
&self,
|
||||||
fields: Option<&HashSet<&str>>,
|
fields: Option<&HashSet<&str>>,
|
||||||
@ -342,3 +357,41 @@ impl Index {
|
|||||||
T::deserialize(&mut deserializer).map(Some)
|
T::deserialize(&mut deserializer).map(Some)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DocumentsAddition(RawIndex);
|
||||||
|
|
||||||
|
impl DocumentsAddition {
|
||||||
|
pub fn from_raw(inner: RawIndex) -> DocumentsAddition {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DocumentsDeletion {
|
||||||
|
inner: RawIndex,
|
||||||
|
documents: Vec<DocumentId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DocumentsDeletion {
|
||||||
|
pub fn from_raw(inner: RawIndex) -> DocumentsDeletion {
|
||||||
|
DocumentsDeletion { inner, documents: Vec::new() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_document(&mut self, id: DocumentId) {
|
||||||
|
self.documents.push(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commit(mut self) -> Result<(), Error> {
|
||||||
|
self.documents.sort_unstable();
|
||||||
|
self.documents.dedup();
|
||||||
|
|
||||||
|
let idset = SetBuf::new_unchecked(self.documents);
|
||||||
|
let index = self.inner.word_index();
|
||||||
|
|
||||||
|
let new_index = index.remove_documents(&idset);
|
||||||
|
let new_index = Arc::from(new_index);
|
||||||
|
|
||||||
|
self.inner.update_word_index(new_index)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user