pub struct Index { /* private fields */ }
Expand description
Search Index
Implementations§
source§impl Index
impl Index
sourcepub fn builder() -> IndexBuilder
pub fn builder() -> IndexBuilder
Creates a new builder.
sourcepub fn exists(dir: &dyn Directory) -> Result<bool, OpenReadError>
pub fn exists(dir: &dyn Directory) -> Result<bool, OpenReadError>
Examines the directory to see if it contains an index.
Effectively, it only checks for the presence of the meta.json
file.
sourcepub fn search_executor(&self) -> &Executor
pub fn search_executor(&self) -> &Executor
Accessor to the search executor.
This pool is used by default when calling searcher.search(...)
to perform search on the individual segments.
By default the executor is single thread, and simply runs in the calling thread.
sourcepub fn set_multithread_executor(&mut self, num_threads: usize) -> Result<()>
pub fn set_multithread_executor(&mut self, num_threads: usize) -> Result<()>
Replace the default single thread search executor pool by a thread pool with a given number of threads.
Custom thread pool by a outer thread pool.
sourcepub fn set_default_multithread_executor(&mut self) -> Result<()>
pub fn set_default_multithread_executor(&mut self) -> Result<()>
Replace the default single thread search executor pool by a thread pool with as many threads as there are CPUs on the system.
sourcepub fn create_in_ram(schema: Schema) -> Index
pub fn create_in_ram(schema: Schema) -> Index
Creates a new index using the RamDirectory
.
The index will be allocated in anonymous memory. This is useful for indexing small set of documents for instances like unit test or temporary in memory index.
sourcepub fn create_in_dir<P: AsRef<Path>>(
directory_path: P,
schema: Schema
) -> Result<Index>
pub fn create_in_dir<P: AsRef<Path>>( directory_path: P, schema: Schema ) -> Result<Index>
Creates a new index in a given filepath.
The index will use the MmapDirectory
.
If a previous index was in this directory, then it returns
a TantivyError::IndexAlreadyExists
error.
sourcepub fn open_or_create<T: Into<Box<dyn Directory>>>(
dir: T,
schema: Schema
) -> Result<Index>
pub fn open_or_create<T: Into<Box<dyn Directory>>>( dir: T, schema: Schema ) -> Result<Index>
Opens or creates a new index in the provided directory
sourcepub fn create_from_tempdir(schema: Schema) -> Result<Index>
pub fn create_from_tempdir(schema: Schema) -> Result<Index>
Creates a new index in a temp directory.
The index will use the MmapDirectory
in a newly created directory.
The temp directory will be destroyed automatically when the Index
object
is destroyed.
The temp directory is only used for testing the MmapDirectory
.
For other unit tests, prefer the RamDirectory
,
see: IndexBuilder::create_in_ram()
.
sourcepub fn create<T: Into<Box<dyn Directory>>>(
dir: T,
schema: Schema,
settings: IndexSettings
) -> Result<Index>
pub fn create<T: Into<Box<dyn Directory>>>( dir: T, schema: Schema, settings: IndexSettings ) -> Result<Index>
Creates a new index given an implementation of the trait Directory
.
If a directory previously existed, it will be erased.
sourcepub fn set_tokenizers(&mut self, tokenizers: TokenizerManager)
pub fn set_tokenizers(&mut self, tokenizers: TokenizerManager)
Setter for the tokenizer manager.
sourcepub fn tokenizers(&self) -> &TokenizerManager
pub fn tokenizers(&self) -> &TokenizerManager
Accessor for the tokenizer manager.
sourcepub fn set_fast_field_tokenizers(&mut self, tokenizers: TokenizerManager)
pub fn set_fast_field_tokenizers(&mut self, tokenizers: TokenizerManager)
Setter for the fast field tokenizer manager.
sourcepub fn fast_field_tokenizer(&self) -> &TokenizerManager
pub fn fast_field_tokenizer(&self) -> &TokenizerManager
Accessor for the fast field tokenizer manager.
sourcepub fn tokenizer_for_field(&self, field: Field) -> Result<TextAnalyzer>
pub fn tokenizer_for_field(&self, field: Field) -> Result<TextAnalyzer>
Get the tokenizer associated with a specific field.
sourcepub fn reader(&self) -> Result<IndexReader>
pub fn reader(&self) -> Result<IndexReader>
Create a default IndexReader
for the given index.
See [Index.reader_builder()
].
sourcepub fn reader_builder(&self) -> IndexReaderBuilder
pub fn reader_builder(&self) -> IndexReaderBuilder
Create a IndexReader
for the given index.
Most project should create at most one reader for a given index.
This method is typically called only once per Index
instance.
sourcepub fn open_in_dir<P: AsRef<Path>>(directory_path: P) -> Result<Index>
pub fn open_in_dir<P: AsRef<Path>>(directory_path: P) -> Result<Index>
Opens a new directory from an index path.
sourcepub fn fields_metadata(&self) -> Result<Vec<FieldMetadata>>
pub fn fields_metadata(&self) -> Result<Vec<FieldMetadata>>
Returns the list of fields that have been indexed in the Index. The field list includes the field defined in the schema as well as the fields that have been indexed as a part of a JSON field. The returned field name is the full field name, including the name of the JSON field.
The returned field names can be used in queries.
Notice: If your data contains JSON fields this is very expensive, as it requires browsing through the inverted index term dictionary and the columnar field dictionary.
Disclaimer: Some fields may not be listed here. For instance, if the schema contains a json field that is not indexed nor a fast field but is stored, it is possible for the field to not be listed.
sourcepub fn new_segment_meta(
&self,
segment_id: SegmentId,
max_doc: u32
) -> SegmentMeta
pub fn new_segment_meta( &self, segment_id: SegmentId, max_doc: u32 ) -> SegmentMeta
Creates a new segment_meta (Advanced user only).
As long as the SegmentMeta
lives, the files associated with the
SegmentMeta
are guaranteed to not be garbage collected, regardless of
whether the segment is recorded as part of the index or not.
sourcepub fn open<T: Into<Box<dyn Directory>>>(directory: T) -> Result<Index>
pub fn open<T: Into<Box<dyn Directory>>>(directory: T) -> Result<Index>
Open the index using the provided directory
sourcepub fn load_metas(&self) -> Result<IndexMeta>
pub fn load_metas(&self) -> Result<IndexMeta>
Reads the index meta file from the directory.
sourcepub fn writer_with_num_threads<D: Document>(
&self,
num_threads: usize,
overall_memory_budget_in_bytes: usize
) -> Result<IndexWriter<D>>
pub fn writer_with_num_threads<D: Document>( &self, num_threads: usize, overall_memory_budget_in_bytes: usize ) -> Result<IndexWriter<D>>
Open a new index writer. Attempts to acquire a lockfile.
The lockfile should be deleted on drop, but it is possible
that due to a panic or other error, a stale lockfile will be
left in the index directory. If you are sure that no other
IndexWriter
on the system is accessing the index directory,
it is safe to manually delete the lockfile.
-
num_threads
defines the number of indexing workers that should work at the same time. -
overall_memory_budget_in_bytes
sets the amount of memory allocated for all indexing thread. Each thread will receive a budget ofoverall_memory_budget_in_bytes / num_threads
.
§Errors
If the lockfile already exists, returns Error::DirectoryLockBusy
or an Error::IoError
.
If the memory arena per thread is too small or too big, returns
TantivyError::InvalidArgument
sourcepub fn writer<D: Document>(
&self,
memory_budget_in_bytes: usize
) -> Result<IndexWriter<D>>
pub fn writer<D: Document>( &self, memory_budget_in_bytes: usize ) -> Result<IndexWriter<D>>
Creates a multithreaded writer
Tantivy will automatically define the number of threads to use, but
no more than 8 threads.
overall_memory_arena_in_bytes
is the total target memory usage that will be split
between a given number of threads.
§Errors
If the lockfile already exists, returns Error::FileAlreadyExists
.
If the memory arena per thread is too small or too big, returns
TantivyError::InvalidArgument
sourcepub fn settings(&self) -> &IndexSettings
pub fn settings(&self) -> &IndexSettings
Accessor to the index settings
sourcepub fn settings_mut(&mut self) -> &mut IndexSettings
pub fn settings_mut(&mut self) -> &mut IndexSettings
Accessor to the index settings
sourcepub fn searchable_segments(&self) -> Result<Vec<Segment>>
pub fn searchable_segments(&self) -> Result<Vec<Segment>>
Returns the list of segments that are searchable
sourcepub fn new_segment(&self) -> Segment
pub fn new_segment(&self) -> Segment
Creates a new segment.
sourcepub fn directory(&self) -> &ManagedDirectory
pub fn directory(&self) -> &ManagedDirectory
Return a reference to the index directory.
sourcepub fn directory_mut(&mut self) -> &mut ManagedDirectory
pub fn directory_mut(&mut self) -> &mut ManagedDirectory
Return a mutable reference to the index directory.
sourcepub fn searchable_segment_metas(&self) -> Result<Vec<SegmentMeta>>
pub fn searchable_segment_metas(&self) -> Result<Vec<SegmentMeta>>
Reads the meta.json and returns the list of
SegmentMeta
from the last commit.
sourcepub fn searchable_segment_ids(&self) -> Result<Vec<SegmentId>>
pub fn searchable_segment_ids(&self) -> Result<Vec<SegmentId>>
Returns the list of segment ids that are searchable.
sourcepub fn validate_checksum(&self) -> Result<HashSet<PathBuf>>
pub fn validate_checksum(&self) -> Result<HashSet<PathBuf>>
Returns the set of corrupted files
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Index
impl !RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl !UnwindSafe for Index
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.