Skip to main content

FTS5Index

Struct FTS5Index 

Source
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

Source

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.
Source

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.

Source

pub fn with_config( db_path: Option<&str>, config: &TreeSearchConfig, ) -> Result<Self>

Creates an index using both FTS weights and tokenizer settings from config.

Source

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.

Source

pub fn db_path(&self) -> &str

Database path (or :memory:).

Source

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).

Source

pub fn index_documents( &self, documents: &[Document], force: bool, ) -> Result<usize>

Batch index multiple documents. Returns total nodes indexed.

Source

pub fn commit(&self) -> Result<()>

Manually commit pending changes to the database.

Source

pub fn set_index_meta_batch(&self, meta: &HashMap<String, String>) -> Result<()>

Batch store/update file hashes. Single transaction for performance.

Source

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.

Source

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).

Source

pub fn search_with_expr( &self, query: &str, doc_id: Option<&str>, top_k: usize, fts_expression: Option<&str>, ) -> Result<Vec<FtsResult>>

Source

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.

Source

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>>>

Source

pub fn save_document(&self, doc: &Document) -> Result<()>

Save a Document’s tree structure (without FTS indexing).

Source

pub fn load_document(&self, doc_id: &str) -> Result<Option<Document>>

Load a single Document by doc_id. Returns None if not found.

Source

pub fn load_all_documents(&self) -> Result<Vec<Document>>

Load all Documents stored in the DB.

Source

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.

Source

pub fn get_index_meta(&self, source_path: &str) -> Result<Option<String>>

Get the stored file hash for a source path.

Source

pub fn set_index_meta(&self, source_path: &str, file_hash: &str) -> Result<()>

Store/update the file hash for a source path.

Source

pub fn get_all_index_meta(&self) -> Result<HashMap<String, String>>

Get all stored file hashes: {source_path: file_hash}.

Source

pub fn get_stats(&self) -> Result<IndexStats>

Get index statistics.

Source

pub fn optimize(&self) -> Result<()>

Run FTS5 merge optimization.

Source

pub fn rebuild(&self) -> Result<()>

Rebuild FTS5 index from scratch.

Source

pub fn clear(&self) -> Result<()>

Clear all indexed data.

Source

pub fn close(self)

Close the database connection.

Consumes the index. After calling close(), no further operations are possible. SQLite flushes WAL and releases all locks.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more