pub trait DocumentSearch {
// Required methods
fn build_index(&mut self, document: &EditorDocument) -> Result<()>;
fn update_index(
&mut self,
document: &EditorDocument,
changes: &[Range],
) -> Result<()>;
fn search<'a>(
&'a self,
pattern: &str,
options: &SearchOptions,
) -> Result<Vec<SearchResult<'a>>>;
fn find_replace<'a>(
&'a self,
document: &mut EditorDocument,
pattern: &str,
replacement: &str,
options: &SearchOptions,
) -> Result<Vec<SearchResult<'a>>>;
fn stats(&self) -> SearchStats;
fn clear_index(&mut self);
}Expand description
Main trait for document search functionality
Provides unified search capabilities with optional FST-based indexing for fast substring searches and regex support for complex pattern matching.
§Examples
use ass_editor::{EditorDocument, utils::search::*};
let mut doc = EditorDocument::from_content(r#"
[Events]
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Hello World
Dialogue: 0,0:00:05.00,0:00:10.00,Default,,0,0,0,,Goodbye World
"#).unwrap();
// Create and use a search instance
let mut search = DocumentSearchImpl::new();
search.build_index(&doc).unwrap();
// Basic text search
let options = SearchOptions::default();
let results = search.search("World", &options).unwrap();
assert_eq!(results.len(), 2);
// Case-insensitive search with options
let options = SearchOptions {
case_sensitive: false,
max_results: 10,
..Default::default()
};Required Methods§
Sourcefn build_index(&mut self, document: &EditorDocument) -> Result<()>
fn build_index(&mut self, document: &EditorDocument) -> Result<()>
Build or rebuild the search index for the document
Sourcefn update_index(
&mut self,
document: &EditorDocument,
changes: &[Range],
) -> Result<()>
fn update_index( &mut self, document: &EditorDocument, changes: &[Range], ) -> Result<()>
Update the search index incrementally after document changes
Sourcefn search<'a>(
&'a self,
pattern: &str,
options: &SearchOptions,
) -> Result<Vec<SearchResult<'a>>>
fn search<'a>( &'a self, pattern: &str, options: &SearchOptions, ) -> Result<Vec<SearchResult<'a>>>
Search for a pattern in the document
Sourcefn find_replace<'a>(
&'a self,
document: &mut EditorDocument,
pattern: &str,
replacement: &str,
options: &SearchOptions,
) -> Result<Vec<SearchResult<'a>>>
fn find_replace<'a>( &'a self, document: &mut EditorDocument, pattern: &str, replacement: &str, options: &SearchOptions, ) -> Result<Vec<SearchResult<'a>>>
Find and replace text in the document
Sourcefn stats(&self) -> SearchStats
fn stats(&self) -> SearchStats
Get search statistics
Sourcefn clear_index(&mut self)
fn clear_index(&mut self)
Clear the search index to free memory
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl DocumentSearch for DocumentSearchImpl
impl DocumentSearch for FstSearchIndex
Available on crate feature
search-index only.