Skip to main content

Crate rusmes_search

Crate rusmes_search 

Source
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 SearchIndex trait is fully async and Send + Sync, making it easy to integrate into Tokio-based protocol handlers.
  • Schema: indexes from, to, subject (TEXT + STORED) and body (TEXT) fields extracted from rusmes_proto::Mail envelopes, plus a stored message_id field for result correlation.
  • Ranked resultssearch returns SearchResult items sorted by Tantivy relevance score.
  • Atomic commits — pending index changes are buffered in memory and flushed to disk only when commit is called, enabling batched indexing.
  • Mutex-guarded writer — the IndexWriter is protected by a std::sync::Mutex so 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§

SearchResult
Search result containing message ID information
TantivySearchIndex
Tantivy-based search index implementation

Enums§

SearchError
Search index errors

Traits§

SearchIndex
Search index trait for message indexing and querying

Type Aliases§

Result