use nodedb_types::Surrogate;
use crate::posting::Posting;
pub trait FtsBackend {
type Error: std::fmt::Display;
fn read_postings(
&self,
database_id: u64,
tid: u64,
collection: &str,
term: &str,
) -> Result<Vec<Posting>, Self::Error>;
fn write_postings(
&self,
database_id: u64,
tid: u64,
collection: &str,
term: &str,
postings: &[Posting],
) -> Result<(), Self::Error>;
fn remove_postings(
&self,
database_id: u64,
tid: u64,
collection: &str,
term: &str,
) -> Result<(), Self::Error>;
fn read_doc_length(
&self,
database_id: u64,
tid: u64,
collection: &str,
doc_id: Surrogate,
) -> Result<Option<u32>, Self::Error>;
fn write_doc_length(
&self,
database_id: u64,
tid: u64,
collection: &str,
doc_id: Surrogate,
length: u32,
) -> Result<(), Self::Error>;
fn remove_doc_length(
&self,
database_id: u64,
tid: u64,
collection: &str,
doc_id: Surrogate,
) -> Result<(), Self::Error>;
fn collection_terms(
&self,
database_id: u64,
tid: u64,
collection: &str,
) -> Result<Vec<String>, Self::Error>;
fn collection_stats(
&self,
database_id: u64,
tid: u64,
collection: &str,
) -> Result<(u32, u64), Self::Error>;
fn increment_stats(
&self,
database_id: u64,
tid: u64,
collection: &str,
doc_len: u32,
) -> Result<(), Self::Error>;
fn decrement_stats(
&self,
database_id: u64,
tid: u64,
collection: &str,
doc_len: u32,
) -> Result<(), Self::Error>;
fn read_meta(
&self,
database_id: u64,
tid: u64,
collection: &str,
subkey: &str,
) -> Result<Option<Vec<u8>>, Self::Error>;
fn write_meta(
&self,
database_id: u64,
tid: u64,
collection: &str,
subkey: &str,
value: &[u8],
) -> Result<(), Self::Error>;
fn write_segment(
&self,
database_id: u64,
tid: u64,
collection: &str,
segment_id: &str,
data: &[u8],
) -> Result<(), Self::Error>;
fn read_segment(
&self,
database_id: u64,
tid: u64,
collection: &str,
segment_id: &str,
) -> Result<Option<Vec<u8>>, Self::Error>;
fn list_segments(
&self,
database_id: u64,
tid: u64,
collection: &str,
) -> Result<Vec<String>, Self::Error>;
fn remove_segment(
&self,
database_id: u64,
tid: u64,
collection: &str,
segment_id: &str,
) -> Result<(), Self::Error>;
fn purge_collection(
&self,
database_id: u64,
tid: u64,
collection: &str,
) -> Result<usize, Self::Error>;
fn purge_tenant(&self, database_id: u64, tid: u64) -> Result<usize, Self::Error>;
}