pub struct SessionIndex { /* private fields */ }Expand description
SQLite-based full-text search index for session messages.
Wraps a Connection to a SQLite database with FTS5 support. The index is
created lazily on first use and must be explicitly updated when sessions change.
Implementations§
Source§impl SessionIndex
impl SessionIndex
Sourcepub fn new(path: &Path) -> Result<Self, IndexError>
pub fn new(path: &Path) -> Result<Self, IndexError>
Open or create a SQLite database at the given path.
The database file is created if it does not exist. The schema is NOT
automatically initialized — call SessionIndex::init_schema after creation.
§Arguments
path— Path to the SQLite database file.
§Errors
Returns an error if the database cannot be opened.
Sourcepub fn init_schema(&self) -> Result<(), IndexError>
pub fn init_schema(&self) -> Result<(), IndexError>
Initialize the database schema.
Creates the sessions table and the messages_fts FTS5 virtual table
if they do not already exist. Safe to call multiple times.
§Errors
Returns an error if the schema cannot be created.
Sourcepub fn index_session(&mut self, session: &Session) -> Result<(), IndexError>
pub fn index_session(&mut self, session: &Session) -> Result<(), IndexError>
Index a session and all its messages.
Upserts the session metadata into the sessions table and inserts all
entries into the messages_fts table. Existing entries for the same session
are deleted before re-indexing to avoid duplicates.
§Arguments
session— The session to index.
§Errors
Returns an error if the index cannot be updated.
Sourcepub fn search(
&self,
query: &str,
limit: usize,
) -> Result<Vec<SearchResult>, IndexError>
pub fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchResult>, IndexError>
Perform a full-text search across all indexed messages.
Returns results ranked by relevance (BM25), with the most relevant first. Each result includes a snippet with matching terms highlighted.
§Arguments
query— The FTS5 search query. Supports FTS5 syntax (e.g.,"exact phrase",term1 OR term2).limit— Maximum number of results to return.
§Errors
Returns an error if the search cannot be executed.
Sourcepub fn list_recent(&self, limit: usize) -> Result<Vec<SessionInfo>, IndexError>
pub fn list_recent(&self, limit: usize) -> Result<Vec<SessionInfo>, IndexError>
Sourcepub fn get_session_info(
&self,
session_id: &str,
) -> Result<Option<SessionInfo>, IndexError>
pub fn get_session_info( &self, session_id: &str, ) -> Result<Option<SessionInfo>, IndexError>
pub fn list_all_session_ids(&self) -> Result<Vec<String>, IndexError>
pub fn delete_session(&mut self, session_id: &str) -> Result<(), IndexError>
Sourcepub fn checkpoint_truncate(&self) -> Result<(), IndexError>
pub fn checkpoint_truncate(&self) -> Result<(), IndexError>
Checkpoint the write-ahead log and truncate it where SQLite can do so safely.
Sourcepub fn vacuum(&self) -> Result<(), IndexError>
pub fn vacuum(&self) -> Result<(), IndexError>
Rebuild the database file to reclaim free pages after explicit cleanup.
Sourcepub fn record_fork(
&mut self,
source_session_id: &str,
forked_session_id: &str,
fork_entry_id: &str,
) -> Result<(), IndexError>
pub fn record_fork( &mut self, source_session_id: &str, forked_session_id: &str, fork_entry_id: &str, ) -> Result<(), IndexError>
Record a fork relationship in the index.
Inserts a row into the forks table linking the source session to the
newly forked session at the specified entry point.
§Arguments
source_session_id— The session ID being forked from.forked_session_id— The new session ID created by the fork.fork_entry_id— The entry ID in the source session where the fork occurred.
§Errors
Returns an error if the fork relationship cannot be recorded.