pub struct Schema(/* private fields */);
Expand description
Tantivy has a very strict schema. You need to specify in advance, whether a field is indexed or not, stored or not, and RAM-based or not.
This is done by creating a schema object, and setting up the fields one by one. It is for the moment impossible to remove fields.
§Examples
use tantivy::schema::*;
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 schema = schema_builder.build();
Implementations§
source§impl Schema
impl Schema
sourcepub fn get_field_entry(&self, field: Field) -> &FieldEntry
pub fn get_field_entry(&self, field: Field) -> &FieldEntry
Return the FieldEntry
associated with a Field
.
sourcepub fn get_field_name(&self, field: Field) -> &str
pub fn get_field_name(&self, field: Field) -> &str
Return the field name for a given Field
.
sourcepub fn num_fields(&self) -> usize
pub fn num_fields(&self) -> usize
Returns the number of fields in the schema.
sourcepub fn fields(&self) -> impl Iterator<Item = (Field, &FieldEntry)>
pub fn fields(&self) -> impl Iterator<Item = (Field, &FieldEntry)>
Return the list of all the Field
s.
sourcepub fn builder() -> SchemaBuilder
pub fn builder() -> SchemaBuilder
Creates a new builder.
sourcepub fn get_field(&self, field_name: &str) -> Result<Field>
pub fn get_field(&self, field_name: &str) -> Result<Field>
Returns the field option associated with a given name.
sourcepub fn find_field<'a>(&self, full_path: &'a str) -> Option<(Field, &'a str)>
pub fn find_field<'a>(&self, full_path: &'a str) -> Option<(Field, &'a str)>
Searches for a full_path in the schema, returning the field name and a JSON path.
This function works by checking if the field exists for the exact given full_path. If it’s not, it splits the full_path at non-escaped ‘.’ chars and tries to match the prefix with the field names, favoring the longest field names.
This does not check if field is a JSON field. It is possible for this functions to return a non-empty JSON path with a non-JSON field.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl PartialEq for Schema
impl PartialEq for Schema
impl Eq for Schema
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
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.