pub struct FTS5Index { /* private fields */ }Expand description
SQLite FTS5 full-text search index for tree-structured documents.
- WAL journal mode for concurrent read/write
- MD-aware columns: title, summary, body, code_blocks, front_matter
- Hierarchical column weighting via bm25() rank function
- Content-hash incremental indexing
- Ancestor score propagation for tree search
In-memory mode (db_path = None): all indexes in :memory:, no file on disk.
Implementations§
Source§impl FTS5Index
impl FTS5Index
Sourcepub fn new(db_path: Option<&str>, weights: Option<FtsWeights>) -> Result<Self>
pub fn new(db_path: Option<&str>, weights: Option<FtsWeights>) -> Result<Self>
Create a new FTS5 index.
db_path = None→ in-memory (:memory:).weights = None→ default column weights.
Sourcepub fn new_path(
db_path: Option<&Path>,
weights: Option<FtsWeights>,
) -> Result<Self>
pub fn new_path( db_path: Option<&Path>, weights: Option<FtsWeights>, ) -> Result<Self>
Creates an index from an OS-native path without requiring UTF-8.
Sourcepub fn with_config(
db_path: Option<&str>,
config: &TreeSearchConfig,
) -> Result<Self>
pub fn with_config( db_path: Option<&str>, config: &TreeSearchConfig, ) -> Result<Self>
Creates an index using both FTS weights and tokenizer settings from config.
Sourcepub fn with_config_path(
db_path: Option<&Path>,
config: &TreeSearchConfig,
) -> Result<Self>
pub fn with_config_path( db_path: Option<&Path>, config: &TreeSearchConfig, ) -> Result<Self>
Creates a configured index from an OS-native path without requiring UTF-8.
Sourcepub fn index_document(&self, doc: &Document, force: bool) -> Result<usize>
pub fn index_document(&self, doc: &Document, force: bool) -> Result<usize>
Index all nodes from a Document into FTS5.
Returns the number of nodes indexed (0 if content hash matches
and force is false).
Sourcepub fn index_documents(
&self,
documents: &[Document],
force: bool,
) -> Result<usize>
pub fn index_documents( &self, documents: &[Document], force: bool, ) -> Result<usize>
Batch index multiple documents. Returns total nodes indexed.
Sourcepub fn set_index_meta_batch(&self, meta: &HashMap<String, String>) -> Result<()>
pub fn set_index_meta_batch(&self, meta: &HashMap<String, String>) -> Result<()>
Batch store/update file hashes. Single transaction for performance.
Sourcepub fn get_doc_id_by_source_path(
&self,
source_path: &str,
) -> Result<Option<String>>
pub fn get_doc_id_by_source_path( &self, source_path: &str, ) -> Result<Option<String>>
Look up a doc_id from a source file path.
Sourcepub fn search(
&self,
query: &str,
doc_id: Option<&str>,
top_k: usize,
) -> Result<Vec<FtsResult>>
pub fn search( &self, query: &str, doc_id: Option<&str>, top_k: usize, ) -> Result<Vec<FtsResult>>
Search nodes using FTS5 BM25 ranking.
Returns results sorted by relevance (highest score first).
pub fn search_with_expr( &self, query: &str, doc_id: Option<&str>, top_k: usize, fts_expression: Option<&str>, ) -> Result<Vec<FtsResult>>
Sourcepub fn score_nodes_batch(
&self,
query: &str,
doc_ids: Option<&[String]>,
ancestor_decay: f64,
) -> Result<HashMap<String, HashMap<String, f64>>>
pub fn score_nodes_batch( &self, query: &str, doc_ids: Option<&[String]>, ancestor_decay: f64, ) -> Result<HashMap<String, HashMap<String, f64>>>
Batch scoring with ancestor propagation.
Returns {doc_id: {node_id: score}} for all matched documents.
Scores are normalized to [0, 1] across the whole candidate set, so
cross-document relevance is preserved before tree reranking.
pub fn score_nodes_batch_with_expr( &self, query: &str, doc_ids: Option<&[String]>, ancestor_decay: f64, fts_expression: Option<&str>, ) -> Result<HashMap<String, HashMap<String, f64>>>
Sourcepub fn save_document(&self, doc: &Document) -> Result<()>
pub fn save_document(&self, doc: &Document) -> Result<()>
Save a Document’s tree structure (without FTS indexing).
Sourcepub fn load_document(&self, doc_id: &str) -> Result<Option<Document>>
pub fn load_document(&self, doc_id: &str) -> Result<Option<Document>>
Load a single Document by doc_id. Returns None if not found.
Sourcepub fn load_all_documents(&self) -> Result<Vec<Document>>
pub fn load_all_documents(&self) -> Result<Vec<Document>>
Load all Documents stored in the DB.
Sourcepub fn delete_document(&self, doc_id: &str) -> Result<bool>
pub fn delete_document(&self, doc_id: &str) -> Result<bool>
Delete a document and all its indexed data atomically.
Returns true if the document existed and was deleted.
Sourcepub fn get_index_meta(&self, source_path: &str) -> Result<Option<String>>
pub fn get_index_meta(&self, source_path: &str) -> Result<Option<String>>
Get the stored file hash for a source path.
Sourcepub fn set_index_meta(&self, source_path: &str, file_hash: &str) -> Result<()>
pub fn set_index_meta(&self, source_path: &str, file_hash: &str) -> Result<()>
Store/update the file hash for a source path.
Sourcepub fn get_all_index_meta(&self) -> Result<HashMap<String, String>>
pub fn get_all_index_meta(&self) -> Result<HashMap<String, String>>
Get all stored file hashes: {source_path: file_hash}.
Sourcepub fn get_stats(&self) -> Result<IndexStats>
pub fn get_stats(&self) -> Result<IndexStats>
Get index statistics.
Auto Trait Implementations§
impl !Freeze for FTS5Index
impl !RefUnwindSafe for FTS5Index
impl !Sync for FTS5Index
impl !UnwindSafe for FTS5Index
impl Send for FTS5Index
impl Unpin for FTS5Index
impl UnsafeUnpin for FTS5Index
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more