use heed::RoTxn; use obkv::KvReader; use crate::update::new::KvReaderFieldId; use crate::{DocumentId, FieldId, Index, Result}; pub enum DocumentChange { Deletion(Deletion), Update(Update), Insertion(Insertion), } pub struct Deletion { docid: DocumentId, current: Box, } pub struct Update { docid: DocumentId, current: Box, new: Box, } pub struct Insertion { docid: DocumentId, new: Box, } impl DocumentChange { pub fn docid(&self) -> DocumentId { match &self { Self::Deletion(inner) => inner.docid(), Self::Update(inner) => inner.docid(), Self::Insertion(inner) => inner.docid(), } } } impl Deletion { pub fn create(docid: DocumentId, current: Box) -> Self { Self { docid, current } } pub fn docid(&self) -> DocumentId { self.docid } // TODO shouldn't we use the one in self? pub fn current<'a>( &self, rtxn: &'a RoTxn, index: &'a Index, ) -> Result>> { index.documents.get(rtxn, &self.docid).map_err(crate::Error::from) } } impl Insertion { pub fn create(docid: DocumentId, new: Box) -> Self { Insertion { docid, new } } pub fn docid(&self) -> DocumentId { self.docid } pub fn new(&self) -> &KvReader { self.new.as_ref() } } impl Update { pub fn create( docid: DocumentId, current: Box, new: Box, ) -> Self { Update { docid, current, new } } pub fn docid(&self) -> DocumentId { self.docid } pub fn current<'a>( &self, rtxn: &'a RoTxn, index: &'a Index, ) -> Result>> { index.documents.get(rtxn, &self.docid).map_err(crate::Error::from) } pub fn new(&self) -> &KvReader { self.new.as_ref() } }