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

source

pub fn new() -> Self

Creates a new IndexBuilder

source

pub fn settings(self, settings: IndexSettings) -> Self

Set the settings

source

pub fn schema(self, schema: Schema) -> Self

Set the schema

source

pub fn tokenizers(self, tokenizers: TokenizerManager) -> Self

Set the tokenizers.

source

pub fn fast_field_tokenizers(self, tokenizers: TokenizerManager) -> Self

Set the fast field tokenizers.

source

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.

source

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.

source

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

source

pub fn open_or_create<T: Into<Box<dyn Directory>>>( self, dir: T ) -> Result<Index>

Opens or creates a new index in the provided directory

Trait Implementations§

source§

impl Default for IndexBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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