pub struct Index<D: DirectoryWriter + 'static> { /* private fields */ }Expand description
Multi-segment async Index
The central concept for search. Owns segment lifecycle and provides:
Index::create()/Index::open()- create or open an indexindex.writer()- get an IndexWriter for adding documentsindex.reader()- get an IndexReader for searching with reload policy
All segment management is delegated to SegmentManager.
Implementations§
Source§impl<D: DirectoryWriter + 'static> Index<D>
impl<D: DirectoryWriter + 'static> Index<D>
Sourcepub async fn create(
directory: D,
schema: Schema,
config: IndexConfig,
) -> Result<Self>
pub async fn create( directory: D, schema: Schema, config: IndexConfig, ) -> Result<Self>
Create a new index in the directory
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 fn segment_manager(&self) -> &Arc<SegmentManager<D>>
pub fn segment_manager(&self) -> &Arc<SegmentManager<D>>
Get the segment manager
Sourcepub fn writer(&self) -> IndexWriter<D>
pub fn writer(&self) -> IndexWriter<D>
Get an IndexWriter for adding documents
Sourcepub async fn reader(&self) -> Result<IndexReader<D>>
pub async fn reader(&self) -> Result<IndexReader<D>>
Get an IndexReader for searching (with reload policy)
Sourcepub fn config(&self) -> &IndexConfig
pub fn config(&self) -> &IndexConfig
Get the config
Sourcepub fn trained_centroids(&self) -> &FxHashMap<u32, Arc<CoarseCentroids>>
pub fn trained_centroids(&self) -> &FxHashMap<u32, Arc<CoarseCentroids>>
Get trained centroids
Sourcepub fn trained_codebooks(&self) -> &FxHashMap<u32, Arc<PQCodebook>>
pub fn trained_codebooks(&self) -> &FxHashMap<u32, Arc<PQCodebook>>
Get trained codebooks
Sourcepub async fn segment_readers(&self) -> Result<Vec<Arc<SegmentReader>>>
pub async fn segment_readers(&self) -> Result<Vec<Arc<SegmentReader>>>
Get segment readers for query execution (convenience method)
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
Sourcepub fn default_fields(&self) -> Vec<Field>
pub fn default_fields(&self) -> Vec<Field>
Get default fields for search
Sourcepub fn tokenizers(&self) -> Arc<TokenizerRegistry>
pub fn tokenizers(&self) -> Arc<TokenizerRegistry>
Get tokenizer registry
Sourcepub fn query_parser(&self) -> QueryLanguageParser
pub fn query_parser(&self) -> QueryLanguageParser
Create a query parser for this index
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
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
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
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 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
Sourcepub async fn reload(&self) -> Result<()>
pub async fn reload(&self) -> Result<()>
Reload is no longer needed - reader handles this automatically
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
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> 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.