pub struct Schema(_);
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
sourceimpl 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 to 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 a named document off the doc.
sourcepub fn to_named_doc(&self, doc: &Document) -> NamedFieldDocument
pub fn to_named_doc(&self, doc: &Document) -> NamedFieldDocument
Create a named document off 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.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Schema
impl StructuralEq for Schema
impl StructuralPartialEq for Schema
Auto Trait Implementations
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
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
sourceimpl<T> DowncastSync for T where
T: Any + Send + Sync,
impl<T> DowncastSync for T where
T: Any + Send + Sync,
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more