Module tantivy::schema [] [src]

Schema definition for tantivy's indices.

Setting your schema in Tantivy

Tantivy has a very strict schema. The schema defines information about the fields your index contains, that is, for each field:

This very last point is critical as it will enable / disable some of the functionality for your index.

Tantivy's schema is stored within the meta.json file at the root of your directory.

Building a schema "programmatically"

Setting a text field

Example

use tantivy::schema::*;
let mut schema_builder = SchemaBuilder::default();
let title_options = TextOptions::default()
    .set_stored()
    .set_indexing_options(TextFieldIndexing::default()
        .set_tokenizer("default")
        .set_index_option(IndexRecordOption::WithFreqsAndPositions));
schema_builder.add_text_field("title_options", title_options);
let schema = schema_builder.build();

We can split the problem of generating a search result page into two phases :

In the first phase, the ability to search for documents by the given field is determined by the TextIndexingOptions of our [TextOptions] (struct.TextOptions.html).

The effect of each possible setting is described more in detail [TextIndexingOptions] (enum.TextIndexingOptions.html).

On the other hand setting the field as stored or not determines whether the field should be returned when searcher.doc(doc_address) is called.

Shortcuts

For convenience, a few special values of TextOptions. They can be composed using the | operator. The example can be rewritten :

use tantivy::schema::*;
let mut schema_builder = SchemaBuilder::default();
schema_builder.add_text_field("title_options", TEXT | STORED);
let schema = schema_builder.build();

Setting a u64 field

Example

use tantivy::schema::*;
let mut schema_builder = SchemaBuilder::default();
let num_stars_options = IntOptions::default()
    .set_stored()
    .set_indexed();
schema_builder.add_u64_field("num_stars", num_stars_options);
let schema = schema_builder.build();

Just like for Text fields (see above), setting the field as stored defines whether the field will be returned when searcher.doc(doc_address) is called, and setting the field as indexed means that we will be able perform queries such as num_stars:10. Note that unlike text fields, u64 can only be indexed in one way for the moment. This may change when we will start supporting range queries.

The fast option on the other hand is specific to u64 fields, and is only relevant if you are implementing your own queries. This functionality is somewhat similar to Lucene's DocValues.

u64 that are indexed as fast will be stored in a special data structure that will make it possible to access the u64 value given the doc id rapidly. This is useful if the value of the field is required during scoring or collection for instance.

Structs

Document

Tantivy's Document is the object that can be indexed and then searched for.

Facet

A Facet represent a point in a given hierarchy.

Field

Field is actually a u8 identifying a Field The schema is in charge of holding mapping between field names to Field objects.

FieldEntry

A FieldEntry represents a field and its configuration. Schema are a collection of FieldEntry

FieldValue

FieldValue holds together a Field and its Value.

IntOptions

Define how an int field should be handled by tantivy.

NamedFieldDocument

Internal representation of a document used for JSON serialization.

Schema

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.

SchemaBuilder

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.

Term

Term represents the value that the token can take.

TextFieldIndexing

Configuration defining indexing for a text field. It wraps:

TextOptions

Define how a text field should be handled by tantivy.

Enums

Cardinality

Express whether a field is single-value or multi-valued.

DocParsingError

Error that may happen when deserializing a document from JSON.

FieldType

A FieldType describes the type (text, u64) of a field as well as how it should be handled by tantivy.

IndexRecordOption

IndexRecordOption describes an amount information associated to a given indexed field.

Value

Value represents the value of a any field. It is an enum over all over all of the possible field type.

Constants

FACET_SEP_BYTE

BYTE used as a level separation in the binary representation of facets.

FAST

Shortcut for a u64 fast field.

INT_INDEXED

Shortcut for a u64 indexed field.

INT_STORED

Shortcut for a u64 stored field.

STORED

A stored fields of a document can be retrieved given its DocId. Stored field are stored together and LZ4 compressed. Reading the stored fields of a document is relatively slow. (100 microsecs)

STRING

The field will be untokenized and indexed

TEXT

The field will be tokenized and indexed

Functions

is_valid_field_name

Validator for a potential field_name. Returns true iff the name can be use for a field name.