mod index;
mod ranking;
mod search;
mod tokenizer;
mod types;
pub use index::*;
pub use ranking::*;
pub use search::*;
pub use tokenizer::*;
pub use types::*;
use alloc::string::String;
use alloc::vec::Vec;
use lazy_static::lazy_static;
use spin::Mutex;
lazy_static! {
static ref FTS_ENGINE: Mutex<FtsEngine> = Mutex::new(FtsEngine::new());
}
pub struct FullTextSearch;
impl FullTextSearch {
pub fn index_file(
dataset: &str,
object_id: u64,
path: &str,
content: &[u8],
) -> Result<(), IndexError> {
let mut engine = FTS_ENGINE.lock();
engine.index_document(dataset, object_id, path, content)
}
pub fn search(
dataset: &str,
query: &str,
options: &SearchOptions,
) -> Result<Vec<SearchHit>, IndexError> {
let engine = FTS_ENGINE.lock();
engine.search(dataset, query, options)
}
pub fn rebuild(dataset: &str) -> Result<IndexStats, IndexError> {
let mut engine = FTS_ENGINE.lock();
engine.rebuild(dataset)
}
pub fn remove_file(dataset: &str, object_id: u64) -> Result<(), IndexError> {
let mut engine = FTS_ENGINE.lock();
engine.remove_document(dataset, object_id)
}
pub fn stats(dataset: &str) -> Result<IndexStats, IndexError> {
let engine = FTS_ENGINE.lock();
engine.get_stats(dataset)
}
}