Index

Struct Index 

Source
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>

Source

pub async fn open(directory: D, config: IndexConfig) -> Result<Self>

Open an existing index from a directory

Source

pub fn schema(&self) -> &Schema

Get the schema

Source

pub fn directory(&self) -> &D

Get a reference to the underlying directory

Source

pub fn num_docs(&self) -> u32

Total number of documents across all segments

Source

pub async fn doc(&self, doc_id: DocId) -> Result<Option<Document>>

Get a document by global doc_id (async)

Source

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)

Source

pub async fn spawn_blocking<F, R>(&self, f: F) -> R
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Execute CPU-intensive work on thread pool (native only)

Source

pub fn segment_readers(&self) -> Vec<Arc<SegmentReader>>

Get segment readers for query execution

Source

pub async fn reload(&self) -> Result<()>

Reload segments from directory (after new segments added)

Source

pub async fn search( &self, query: &dyn Query, limit: usize, ) -> Result<Vec<SearchResult>>

Search across all segments

Source

pub async fn search_with_addresses( &self, query: &dyn Query, limit: usize, ) -> Result<SearchResponse>

Search and return results with document addresses (no document content)

Source

pub async fn get_document( &self, address: &DocAddress, ) -> Result<Option<Document>>

Get a document by its unique address (segment_id + local doc_id)

Source

pub fn default_fields(&self) -> &[Field]

Get the default fields for this index

Source

pub fn set_default_fields(&mut self, fields: Vec<Field>)

Set the default fields for query parsing

Source

pub fn tokenizers(&self) -> &Arc<TokenizerRegistry>

Get the tokenizer registry

Source

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.

Source

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.

Source§

impl<D: Directory> Index<SliceCachingDirectory<D>>

Methods for opening index with slice caching

Source

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.

Source

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.

Source

pub fn slice_cache_stats(&self) -> SliceCacheStats

Get slice cache statistics

Trait Implementations§

Source§

impl<D: Directory> Clone for Index<D>

Available on crate feature native only.
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V