Schema definition for tantivy's indices.
Tantivy has a very strict schema. The schema defines information about the fields your index contains, that is, for each field:
- the field name (may only contain letters
- the type of the field (currently only
- how the field should be indexed / stored.
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
use tantivy::schema::*; let mut schema_builder = Schema::builder(); 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", title_options); let schema = schema_builder.build();
We can split the problem of generating a search result page into two phases :
- identifying the list of 10 or so documents to be displayed (Conceptually
query -> doc_ids)
- for each of these documents, retrieving the information required to generate
the search results page. (
doc_ids -> Document)
The effect of each possible setting is described more in detail
On the other hand setting the field as stored or not determines whether the field should be returned
searcher.doc(doc_address) is called.
use tantivy::schema::*; let mut schema_builder = Schema::builder(); 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
searcher.doc(doc_address) is called,
and setting the field as indexed means that we will be able perform queries such as
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.
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
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.
For convenience, it is possible to define your field indexing options by combining different flags
For instance, a schema containing the two fields defined in the example above could be rewritten :
use tantivy::schema::*; let mut schema_builder = Schema::builder(); schema_builder.add_u64_field("num_stars", INDEXED | STORED); schema_builder.add_text_field("title", TEXT | STORED); let schema = schema_builder.build();
Tantivy's Document is the object that can be indexed and then searched for.
A Facet represent a point in a given hierarchy.
Define how an int field should be handled by tantivy.
Internal representation of a document used for JSON serialization.
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.
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 represents the value that the token can take.
Configuration defining indexing for a text field.
Define how a text field should be handled by tantivy.
Express whether a field is single-value or multi-valued.
Error that may happen when deserializing a document from JSON.
Type of the value that a field can take.
Value represents the value of a any field. It is an enum over all over all of the possible field type.
Flag to mark the field as a fast field (similar to Lucene's DocValues)
Flag to mark the field as indexed.
Flag to mark the field as stored. This flag can apply to any kind of field.
The field will be untokenized and indexed
The field will be tokenized and indexed
Validator for a potential