typstify_search/
lib.rs

1//! Typstify Search Library
2//!
3//! Search index generation with Tantivy for full-text search capabilities.
4//!
5//! # Features
6//!
7//! - **Tantivy-based indexing**: Full-text search with language-aware tokenization
8//! - **Index chunking**: Split large indexes for efficient browser loading
9//! - **Simple index**: Lightweight JSON-based alternative for small sites
10//!
11//! # Example
12//!
13//! ```no_run
14//! use std::path::Path;
15//!
16//! use typstify_search::{IndexerConfig, SearchIndexer, SimpleSearchIndex};
17//!
18//! // Build a Tantivy index
19//! let indexer =
20//!     SearchIndexer::new(Path::new("./search-index"), IndexerConfig::default()).unwrap();
21//! // indexer.index_pages(&pages)?;
22//!
23//! // Or use simple JSON index for small sites
24//! // let simple_index = SimpleSearchIndex::from_pages(&pages);
25//! // simple_index.write_to_file(Path::new("search.json"))?;
26//! ```
27
28pub mod chunker;
29pub mod indexer;
30pub mod schema;
31pub mod simple;
32
33pub use chunker::{ChunkerConfig, FileManifest, IndexChunker, IndexManifest};
34pub use indexer::{IndexStats, IndexerConfig, SearchIndexer};
35pub use schema::{SearchFields, create_search_schema, register_tokenizers};
36pub use simple::{MAX_SIMPLE_INDEX_SIZE, SimpleDocument, SimpleSearchIndex};
37use thiserror::Error;
38
39/// Search-related errors.
40#[derive(Debug, Error)]
41pub enum SearchError {
42    /// I/O error.
43    #[error("I/O error: {0}")]
44    Io(String),
45
46    /// Index error.
47    #[error("Index error: {0}")]
48    Index(String),
49
50    /// Serialization error.
51    #[error("Serialization error: {0}")]
52    Serialization(String),
53
54    /// Query error.
55    #[error("Query error: {0}")]
56    Query(String),
57}
58
59/// Result type for search operations.
60pub type Result<T> = std::result::Result<T, SearchError>;