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) -> Option<Field>
pub fn get_field(&self, field_name: &str) -> Option<Field>
Returns the field option associated with a given name.
Sourcepub fn convert_named_doc(
&self,
named_doc: NamedFieldDocument,
) -> Result<Document, DocParsingError>
pub fn convert_named_doc( &self, named_doc: NamedFieldDocument, ) -> Result<Document, DocParsingError>
Create document from a named doc.
Sourcepub fn to_named_doc(&self, doc: &Document) -> NamedFieldDocument
pub fn to_named_doc(&self, doc: &Document) -> NamedFieldDocument
Create a named document from the doc.
Sourcepub fn to_json(&self, doc: &Document) -> String
pub fn to_json(&self, doc: &Document) -> String
Encode the schema in JSON.
Encoding a document cannot fail.
Sourcepub fn parse_document(
&self,
doc_json: &str,
) -> Result<Document, DocParsingError>
pub fn parse_document( &self, doc_json: &str, ) -> Result<Document, DocParsingError>
Build a document object from a json-object.
Sourcepub fn json_object_to_doc(
&self,
json_obj: Map<String, JsonValue>,
) -> Result<Document, DocParsingError>
pub fn json_object_to_doc( &self, json_obj: Map<String, JsonValue>, ) -> Result<Document, DocParsingError>
Build a document object from a json-object.
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>,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more