Struct tantivy::index::Index

source ·
pub struct Index { /* private fields */ }
Expand description

Search Index

Implementations§

source§

impl Index

source

pub fn builder() -> IndexBuilder

Creates a new builder.

source

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.

source

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.

source

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.

source

pub fn set_shared_multithread_executor( &mut self, shared_thread_pool: Arc<Executor> ) -> Result<()>

Custom thread pool by a outer thread pool.

source

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.

source

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.

source

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.

source

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

source

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().

source

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.

source

pub fn set_tokenizers(&mut self, tokenizers: TokenizerManager)

Setter for the tokenizer manager.

source

pub fn tokenizers(&self) -> &TokenizerManager

Accessor for the tokenizer manager.

source

pub fn set_fast_field_tokenizers(&mut self, tokenizers: TokenizerManager)

Setter for the fast field tokenizer manager.

source

pub fn fast_field_tokenizer(&self) -> &TokenizerManager

Accessor for the fast field tokenizer manager.

source

pub fn tokenizer_for_field(&self, field: Field) -> Result<TextAnalyzer>

Get the tokenizer associated with a specific field.

source

pub fn reader(&self) -> Result<IndexReader>

Create a default IndexReader for the given index.

See [Index.reader_builder()].

source

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.

source

pub fn open_in_dir<P: AsRef<Path>>(directory_path: P) -> Result<Index>

Opens a new directory from an index path.

source

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.

source

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.

source

pub fn open<T: Into<Box<dyn Directory>>>(directory: T) -> Result<Index>

Open the index using the provided directory

source

pub fn load_metas(&self) -> Result<IndexMeta>

Reads the index meta file from the directory.

source

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 of overall_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

source

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

source

pub fn settings(&self) -> &IndexSettings

Accessor to the index settings

source

pub fn settings_mut(&mut self) -> &mut IndexSettings

Accessor to the index settings

source

pub fn schema(&self) -> Schema

Accessor to the index schema

The schema is actually cloned.

source

pub fn searchable_segments(&self) -> Result<Vec<Segment>>

Returns the list of segments that are searchable

source

pub fn new_segment(&self) -> Segment

Creates a new segment.

source

pub fn directory(&self) -> &ManagedDirectory

Return a reference to the index directory.

source

pub fn directory_mut(&mut self) -> &mut ManagedDirectory

Return a mutable reference to the index directory.

source

pub fn searchable_segment_metas(&self) -> Result<Vec<SegmentMeta>>

Reads the meta.json and returns the list of SegmentMeta from the last commit.

source

pub fn searchable_segment_ids(&self) -> Result<Vec<SegmentId>>

Returns the list of segment ids that are searchable.

source

pub fn validate_checksum(&self) -> Result<HashSet<PathBuf>>

Returns the set of corrupted files

Trait Implementations§

source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Index

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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,

§

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

§

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

§

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<T> Fruit for T
where T: Send + Downcast,