2024-08-28 18:45:16 +02:00
|
|
|
use heed::RoTxn;
|
2024-08-29 19:20:10 +02:00
|
|
|
use obkv::KvReader;
|
2024-08-28 18:45:16 +02:00
|
|
|
|
2024-09-02 10:42:19 +02:00
|
|
|
use crate::update::new::KvReaderFieldId;
|
2024-09-03 15:14:16 +02:00
|
|
|
use crate::{DocumentId, FieldId, Index, Result};
|
2024-08-28 18:45:16 +02:00
|
|
|
|
|
|
|
pub enum DocumentChange {
|
|
|
|
Deletion(Deletion),
|
|
|
|
Update(Update),
|
|
|
|
Insertion(Insertion),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Deletion {
|
|
|
|
docid: DocumentId,
|
2024-09-12 18:01:02 +02:00
|
|
|
current: Box<KvReaderFieldId>,
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Update {
|
|
|
|
docid: DocumentId,
|
2024-09-12 18:01:02 +02:00
|
|
|
current: Box<KvReaderFieldId>,
|
2024-08-28 18:45:16 +02:00
|
|
|
new: Box<KvReaderFieldId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Insertion {
|
|
|
|
docid: DocumentId,
|
|
|
|
new: Box<KvReaderFieldId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DocumentChange {
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn docid(&self) -> DocumentId {
|
2024-08-28 18:45:16 +02:00
|
|
|
match &self {
|
|
|
|
Self::Deletion(inner) => inner.docid(),
|
|
|
|
Self::Update(inner) => inner.docid(),
|
|
|
|
Self::Insertion(inner) => inner.docid(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deletion {
|
2024-09-12 18:01:02 +02:00
|
|
|
pub fn create(docid: DocumentId, current: Box<KvReaderFieldId>) -> Self {
|
|
|
|
Self { docid, current }
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn docid(&self) -> DocumentId {
|
2024-08-28 18:45:16 +02:00
|
|
|
self.docid
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:03:09 +02:00
|
|
|
// TODO shouldn't we use the one in self?
|
2024-09-03 15:14:16 +02:00
|
|
|
pub fn current<'a>(
|
|
|
|
&self,
|
|
|
|
rtxn: &'a RoTxn,
|
|
|
|
index: &'a Index,
|
|
|
|
) -> Result<Option<&'a KvReader<FieldId>>> {
|
|
|
|
index.documents.get(rtxn, &self.docid).map_err(crate::Error::from)
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Insertion {
|
2024-09-12 18:01:02 +02:00
|
|
|
pub fn create(docid: DocumentId, new: Box<KvReaderFieldId>) -> Self {
|
|
|
|
Insertion { docid, new }
|
2024-08-29 12:06:44 +02:00
|
|
|
}
|
|
|
|
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn docid(&self) -> DocumentId {
|
2024-08-28 18:45:16 +02:00
|
|
|
self.docid
|
|
|
|
}
|
|
|
|
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn new(&self) -> &KvReader<FieldId> {
|
2024-09-03 15:14:16 +02:00
|
|
|
self.new.as_ref()
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Update {
|
2024-08-29 12:06:44 +02:00
|
|
|
pub fn create(
|
|
|
|
docid: DocumentId,
|
|
|
|
current: Box<KvReaderFieldId>,
|
|
|
|
new: Box<KvReaderFieldId>,
|
|
|
|
) -> Self {
|
2024-09-12 18:01:02 +02:00
|
|
|
Update { docid, current, new }
|
2024-08-29 12:06:44 +02:00
|
|
|
}
|
|
|
|
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn docid(&self) -> DocumentId {
|
2024-08-28 18:45:16 +02:00
|
|
|
self.docid
|
|
|
|
}
|
|
|
|
|
2024-09-03 15:14:16 +02:00
|
|
|
pub fn current<'a>(
|
|
|
|
&self,
|
|
|
|
rtxn: &'a RoTxn,
|
|
|
|
index: &'a Index,
|
|
|
|
) -> Result<Option<&'a KvReader<FieldId>>> {
|
|
|
|
index.documents.get(rtxn, &self.docid).map_err(crate::Error::from)
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
|
2024-09-03 11:02:39 +02:00
|
|
|
pub fn new(&self) -> &KvReader<FieldId> {
|
2024-09-03 15:14:16 +02:00
|
|
|
self.new.as_ref()
|
2024-08-28 18:45:16 +02:00
|
|
|
}
|
|
|
|
}
|