Struct tantivy::index::IndexBuilder
source · pub struct IndexBuilder { /* private fields */ }
Expand description
IndexBuilder can be used to create an index.
Use in conjunction with SchemaBuilder
.
Global index settings can be configured with IndexSettings
.
§Examples
use tantivy::schema::*;
use tantivy::{Index, IndexSettings};
let mut schema_builder = Schema::builder();
let id_field = schema_builder.add_text_field("id", STRING);
let title_field = schema_builder.add_text_field("title", TEXT);
let body_field = schema_builder.add_text_field("body", TEXT);
let number_field = schema_builder.add_u64_field(
"number",
NumericOptions::default().set_fast(),
);
let schema = schema_builder.build();
let settings = IndexSettings{
docstore_blocksize: 100_000,
..Default::default()
};
let index = Index::builder().schema(schema).settings(settings).create_in_ram();
Implementations§
source§impl IndexBuilder
impl IndexBuilder
sourcepub fn settings(self, settings: IndexSettings) -> Self
pub fn settings(self, settings: IndexSettings) -> Self
Set the settings
sourcepub fn tokenizers(self, tokenizers: TokenizerManager) -> Self
pub fn tokenizers(self, tokenizers: TokenizerManager) -> Self
Set the tokenizers.
sourcepub fn fast_field_tokenizers(self, tokenizers: TokenizerManager) -> Self
pub fn fast_field_tokenizers(self, tokenizers: TokenizerManager) -> Self
Set the fast field tokenizers.
sourcepub fn create_in_ram(self) -> Result<Index, TantivyError>
pub fn create_in_ram(self) -> Result<Index, TantivyError>
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>>(self, directory_path: P) -> Result<Index>
pub fn create_in_dir<P: AsRef<Path>>(self, directory_path: P) -> Result<Index>
Creates a new index in a given filepath.
The index will use the MmapDirectory
.
If a previous index was in this directory, it returns an
TantivyError::IndexAlreadyExists
error.
sourcepub fn create_from_tempdir(self) -> Result<Index>
pub fn create_from_tempdir(self) -> 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()
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IndexBuilder
impl RefUnwindSafe for IndexBuilder
impl Send for IndexBuilder
impl Sync for IndexBuilder
impl Unpin for IndexBuilder
impl UnwindSafe for IndexBuilder
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.