Expand description
Full-text search for RusMES
This crate provides a Tantivy-backed full-text search index for mail messages. It exposes a trait-based abstraction so that the rest of the RusMES system can remain decoupled from the underlying search engine.
§Key Features
- Tantivy back-end — uses Tantivy for on-disk inverted-index full-text search with BM25 ranking.
- Async interface — the
SearchIndextrait is fullyasyncandSend + Sync, making it easy to integrate into Tokio-based protocol handlers. - Schema: indexes
from,to,subject(TEXT + STORED) andbody(TEXT) fields extracted fromrusmes_proto::Mailenvelopes, plus a storedmessage_idfield for result correlation. - Ranked results —
searchreturnsSearchResultitems sorted by Tantivy relevance score. - Atomic commits — pending index changes are buffered in memory and flushed to disk
only when
commitis called, enabling batched indexing. - Mutex-guarded writer — the
IndexWriteris protected by astd::sync::Mutexso that multiple async tasks can share the same index safely.
§Usage
use rusmes_search::{TantivySearchIndex, SearchIndex};
use std::path::Path;
// Create or open an index at the given path
let index = TantivySearchIndex::new("/var/lib/rusmes/search")?;
// Search (returns up to `limit` results ranked by relevance)
let results = index.search("quarterly report", 10).await?;
for r in &results {
println!("message_uuid={} score={}", r.message_uuid, r.score);
}
// Commit pending writes before querying new documents
index.commit().await?;§Opening vs Creating
Use TantivySearchIndex::new when creating an index for the first time.
Use TantivySearchIndex::open to reopen an existing index after a restart.
Both paths fail with a SearchError if the directory cannot be accessed or the
schema is incompatible.
§Error Handling
All fallible operations return Result<T> which aliases
std::result::Result<T, SearchError>. The SearchError enum covers Tantivy
engine errors, query parse failures, I/O errors, and missing-message conditions.
Structs§
- Search
Result - Search result containing message ID information
- Tantivy
Search Index - Tantivy-based search index implementation
Enums§
- Search
Error - Search index errors
Traits§
- Search
Index - Search index trait for message indexing and querying