Struct tantivy::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, IndexSortByField, Order};
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(Cardinality::SingleValue),
);
let schema = schema_builder.build();
let settings = IndexSettings{sort_by_field: Some(IndexSortByField{field:"number".to_string(), order:Order::Asc}), ..Default::default()};
let index = Index::builder().schema(schema).settings(settings).create_in_ram();
Implementations
sourceimpl 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 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 should only be used for unit tests.
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 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: create_in_ram
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for IndexBuilder
impl Send for IndexBuilder
impl Sync for IndexBuilder
impl Unpin for IndexBuilder
impl UnwindSafe for IndexBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
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. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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. Read more