pub struct Index<D: Directory> { /* private fields */ }Expand description
Multi-segment async Index
The main entry point for searching. Manages multiple segments and provides unified search across all of them.
Implementations§
Source§impl<D: Directory> Index<D>
impl<D: Directory> Index<D>
Sourcepub async fn open(directory: D, config: IndexConfig) -> Result<Self>
pub async fn open(directory: D, config: IndexConfig) -> Result<Self>
Open an existing index from a directory
Sourcepub async fn doc(&self, doc_id: DocId) -> Result<Option<Document>>
pub async fn doc(&self, doc_id: DocId) -> Result<Option<Document>>
Get a document by global doc_id (async)
Sourcepub async fn get_postings(
&self,
field: Field,
term: &[u8],
) -> Result<Vec<(Arc<SegmentReader>, BlockPostingList)>>
pub async fn get_postings( &self, field: Field, term: &[u8], ) -> Result<Vec<(Arc<SegmentReader>, BlockPostingList)>>
Get posting lists for a term across all segments (async)
Sourcepub async fn spawn_blocking<F, R>(&self, f: F) -> R
pub async fn spawn_blocking<F, R>(&self, f: F) -> R
Execute CPU-intensive work on thread pool (native only)
Sourcepub fn segment_readers(&self) -> Vec<Arc<SegmentReader>>
pub fn segment_readers(&self) -> Vec<Arc<SegmentReader>>
Get segment readers for query execution
Sourcepub async fn reload(&self) -> Result<()>
pub async fn reload(&self) -> Result<()>
Reload segments from directory (after new segments added)
Sourcepub fn global_stats(&self) -> Option<Arc<GlobalStats>>
pub fn global_stats(&self) -> Option<Arc<GlobalStats>>
Get global statistics for cross-segment IDF computation (sync, basic stats only)
Returns cached stats if available. For full stats including term frequencies,
call build_global_stats().await first.
This sync version only includes:
- Total docs
- Sparse vector dimension document frequencies
- Average field lengths
Sourcepub async fn build_global_stats(&self) -> Result<Arc<GlobalStats>>
pub async fn build_global_stats(&self) -> Result<Arc<GlobalStats>>
Build and cache global statistics (async, includes term frequencies)
This iterates term dictionaries across all segments to compute accurate cross-segment IDF values for full-text queries.
Call this once after opening the index or after reload().
Sourcepub async fn search(
&self,
query: &dyn Query,
limit: usize,
) -> Result<SearchResponse>
pub async fn search( &self, query: &dyn Query, limit: usize, ) -> Result<SearchResponse>
Search and return results with document addresses (no document content)
This is the primary search method. Use get_document to fetch document content.
Sourcepub async fn search_offset(
&self,
query: &dyn Query,
limit: usize,
offset: usize,
) -> Result<SearchResponse>
pub async fn search_offset( &self, query: &dyn Query, limit: usize, offset: usize, ) -> Result<SearchResponse>
Search with offset for pagination
Sourcepub async fn search_with_matched_fields(
&self,
query: &dyn Query,
limit: usize,
) -> Result<SearchResponse>
pub async fn search_with_matched_fields( &self, query: &dyn Query, limit: usize, ) -> Result<SearchResponse>
Search with matched field ordinals (for multi-valued fields with position tracking)
Returns which array elements matched for each field with position tracking enabled.
Sourcepub async fn get_document(
&self,
address: &DocAddress,
) -> Result<Option<Document>>
pub async fn get_document( &self, address: &DocAddress, ) -> Result<Option<Document>>
Get a document by its unique address (segment_id + local doc_id)
Sourcepub fn default_fields(&self) -> &[Field]
pub fn default_fields(&self) -> &[Field]
Get the default fields for this index
Sourcepub fn set_default_fields(&mut self, fields: Vec<Field>)
pub fn set_default_fields(&mut self, fields: Vec<Field>)
Set the default fields for query parsing
Sourcepub fn tokenizers(&self) -> &Arc<TokenizerRegistry>
pub fn tokenizers(&self) -> &Arc<TokenizerRegistry>
Get the tokenizer registry
Sourcepub fn query_parser(&self) -> QueryLanguageParser
pub fn query_parser(&self) -> QueryLanguageParser
Create a query parser for this index
If the schema contains query router rules, they will be used to route queries to specific fields based on regex patterns.
Sourcepub async fn query(
&self,
query_str: &str,
limit: usize,
) -> Result<SearchResponse>
pub async fn query( &self, query_str: &str, limit: usize, ) -> Result<SearchResponse>
Parse and search using a query string
Accepts both query language syntax (field:term, AND, OR, NOT, grouping) and simple text (tokenized and searched across default fields). Returns document addresses (segment_id + doc_id) without document content.
Sourcepub async fn query_offset(
&self,
query_str: &str,
limit: usize,
offset: usize,
) -> Result<SearchResponse>
pub async fn query_offset( &self, query_str: &str, limit: usize, offset: usize, ) -> Result<SearchResponse>
Query with offset for pagination
Source§impl<D: Directory> Index<SliceCachingDirectory<D>>
Methods for opening index with slice caching
impl<D: Directory> Index<SliceCachingDirectory<D>>
Methods for opening index with slice caching
Sourcepub async fn open_with_cache(
directory: D,
config: IndexConfig,
cache_max_bytes: usize,
) -> Result<Self>
pub async fn open_with_cache( directory: D, config: IndexConfig, cache_max_bytes: usize, ) -> Result<Self>
Open an index with slice caching, automatically loading the cache file if present
This wraps the directory in a SliceCachingDirectory and attempts to load any existing slice cache file to prefill the cache with hot data.
Sourcepub async fn save_slice_cache(&self) -> Result<()>where
D: DirectoryWriter,
pub async fn save_slice_cache(&self) -> Result<()>where
D: DirectoryWriter,
Serialize the current slice cache to the index directory
This saves all cached slices to a single file that can be loaded on subsequent index opens for faster startup.
Sourcepub fn slice_cache_stats(&self) -> SliceCacheStats
pub fn slice_cache_stats(&self) -> SliceCacheStats
Get slice cache statistics
Trait Implementations§
Auto Trait Implementations§
impl<D> !Freeze for Index<D>
impl<D> !RefUnwindSafe for Index<D>
impl<D> Send for Index<D>
impl<D> Sync for Index<D>
impl<D> Unpin for Index<D>
impl<D> !UnwindSafe for Index<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.