use crate::{
backend::FtsBackend,
lsm::memtable::{Memtable, MemtableConfig},
posting::Bm25Params,
};
use nodedb_mem::MemoryGovernor;
use std::sync::{Arc, atomic::AtomicU64};
pub struct FtsIndex<B: FtsBackend> {
pub(crate) backend: B,
pub(crate) bm25_params: Bm25Params,
pub(crate) memtable: Memtable,
pub(super) next_segment_id: AtomicU64,
pub(crate) governor: Arc<MemoryGovernor>,
}
impl<B: FtsBackend> FtsIndex<B> {
pub fn new(backend: B, governor: Arc<MemoryGovernor>) -> Self {
Self {
backend,
bm25_params: Bm25Params::default(),
memtable: Memtable::new(MemtableConfig::default()),
next_segment_id: AtomicU64::new(1),
governor,
}
}
pub fn with_params(backend: B, params: Bm25Params, governor: Arc<MemoryGovernor>) -> Self {
Self {
bm25_params: params,
..Self::new(backend, governor)
}
}
pub fn with_memtable_config(
backend: B,
memtable: MemtableConfig,
governor: Arc<MemoryGovernor>,
) -> Self {
Self {
memtable: Memtable::new(memtable),
..Self::new(backend, governor)
}
}
pub fn with_config(
backend: B,
params: Bm25Params,
memtable: MemtableConfig,
governor: Arc<MemoryGovernor>,
) -> Self {
Self {
bm25_params: params,
memtable: Memtable::new(memtable),
..Self::new(backend, governor)
}
}
pub fn backend(&self) -> &B {
&self.backend
}
pub fn backend_mut(&mut self) -> &mut B {
&mut self.backend
}
pub fn memtable(&self) -> &Memtable {
&self.memtable
}
}