//! Persistence boundary. A read view must represent a single committed revision. use crate::{Document, DocumentId}; use std::{borrow::Cow, collections::BTreeMap}; pub type Postings = BTreeMap; #[derive(Clone, Debug)] pub struct IndexedDocument { pub document: Document, pub title: String, pub body: String, pub lengths: [usize; 2], pub frequencies: BTreeMap, } pub trait IndexReader { type Error; /// Document count and total token counts in the short and body fields. fn statistics(&self) -> Result<(usize, [usize; 2]), Self::Error>; fn postings(&self, term: &str) -> Result>, Self::Error>; /// IDs come from this snapshot's posting lists and must resolve. fn document(&self, id: DocumentId) -> Result, Self::Error>; } pub trait IndexStore { type Error; type Reader<'a>: IndexReader where Self: 'a; fn snapshot(&self) -> Result, Self::Error>; /// Atomically replace the old document, its postings and field statistics. fn replace(&mut self, entry: IndexedDocument) -> Result<(), Self::Error>; fn delete(&mut self, id: DocumentId) -> Result; }