| <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Schema definition for tantivy’s indices."><meta name="keywords" content="rust, rustlang, rust-lang, schema"><title>tantivy::schema - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../tantivy/index.html"><div class="logo-container"><img src="http://fulmicoton.com/tantivy-logo/tantivy-logo.png" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../tantivy/index.html"><div class="logo-container"> |
| <img src="http://fulmicoton.com/tantivy-logo/tantivy-logo.png" alt="logo"></div></a><h2 class="location"><a href="#">Module schema</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">tantivy</a>::<wbr><a class="mod" href="#">schema</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/tantivy/schema/mod.rs.html#1-172">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Schema definition for tantivy’s indices.</p> |
| <h2 id="setting-your-schema-in-tantivy"><a href="#setting-your-schema-in-tantivy">Setting your schema in Tantivy</a></h2> |
| <p>Tantivy has a very strict schema. |
| The schema defines information about the fields your index contains, that is, for each field:</p> |
| <ul> |
| <li>the field name (may only contain letters <code>[a-zA-Z]</code>, number <code>[0-9]</code>, and <code>_</code>)</li> |
| <li>the type of the field (currently only <code>text</code> and <code>u64</code> are supported)</li> |
| <li>how the field should be indexed / stored.</li> |
| </ul> |
| <p>This very last point is critical as it will enable / disable some of the functionality |
| for your index.</p> |
| <p>Tantivy’s schema is stored within the <code>meta.json</code> file at the root of your |
| directory.</p> |
| <h2 id="building-a-schema-programmatically"><a href="#building-a-schema-programmatically">Building a schema “programmatically”</a></h2><h3 id="setting-a-text-field"><a href="#setting-a-text-field">Setting a text field</a></h3><h4 id="example"><a href="#example">Example</a></h4> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::schema::<span class="kw-2">*</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>schema_builder = Schema::builder(); |
| <span class="kw">let </span>title_options = TextOptions::default() |
| .set_stored() |
| .set_indexing_options(TextFieldIndexing::default() |
| .set_tokenizer(<span class="string">"default"</span>) |
| .set_index_option(IndexRecordOption::WithFreqsAndPositions)); |
| schema_builder.add_text_field(<span class="string">"title"</span>, title_options); |
| <span class="kw">let </span>schema = schema_builder.build();</code></pre></div> |
| <p>We can split the problem of generating a search result page into two phases:</p> |
| <ul> |
| <li>identifying the list of 10 or so documents to be displayed (Conceptually <code>query -> doc_ids[]</code>)</li> |
| <li>for each of these documents, retrieving the information required to generate the search |
| results page. (<code>doc_ids[] -> Document[]</code>)</li> |
| </ul> |
| <p>In the first phase, the ability to search for documents by the given field is determined by the |
| <a href="enum.IndexRecordOption.html" title="IndexRecordOption"><code>IndexRecordOption</code></a> of our <a href="struct.TextOptions.html" title="TextOptions"><code>TextOptions</code></a>.</p> |
| <p>The effect of each possible setting is described more in detail in <a href="struct.TextOptions.html" title="TextOptions"><code>TextOptions</code></a>.</p> |
| <p>On the other hand setting the field as stored or not determines whether the field should be |
| returned when <a href="../struct.Searcher.html#method.doc"><code>Searcher::doc()</code></a> is called.</p> |
| <h3 id="setting-a-u64-a-i64-or-a-f64-field"><a href="#setting-a-u64-a-i64-or-a-f64-field">Setting a u64, a i64 or a f64 field</a></h3><h4 id="example-1"><a href="#example-1">Example</a></h4> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::schema::<span class="kw-2">*</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>schema_builder = Schema::builder(); |
| <span class="kw">let </span>num_stars_options = NumericOptions::default() |
| .set_stored() |
| .set_indexed(); |
| schema_builder.add_u64_field(<span class="string">"num_stars"</span>, num_stars_options); |
| <span class="kw">let </span>schema = schema_builder.build();</code></pre></div> |
| <p>Just like for Text fields (see above), |
| setting the field as stored defines whether the field will be |
| returned when <a href="../struct.Searcher.html#method.doc"><code>Searcher::doc()</code></a> is called, |
| and setting the field as indexed means that we will be able perform queries such as |
| <code>num_stars:10</code>. Note that unlike text fields, numeric fields can only be indexed in one way for |
| the moment.</p> |
| <h4 id="shortcuts"><a href="#shortcuts">Shortcuts</a></h4> |
| <p>For convenience, it is possible to define your field indexing options by combining different |
| flags using the <code>|</code> operator.</p> |
| <p>For instance, a schema containing the two fields defined in the example above could be |
| rewritten:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::schema::<span class="kw-2">*</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>schema_builder = Schema::builder(); |
| schema_builder.add_u64_field(<span class="string">"num_stars"</span>, INDEXED | STORED); |
| schema_builder.add_text_field(<span class="string">"title"</span>, TEXT | STORED); |
| <span class="kw">let </span>schema = schema_builder.build();</code></pre></div> |
| <h4 id="fast-fields"><a href="#fast-fields">Fast fields</a></h4> |
| <p>This functionality is somewhat similar to Lucene’s <code>DocValues</code>.</p> |
| <p>Fields that are indexed as <a href="constant.FAST.html" title="FAST"><code>FAST</code></a> will be stored in a special data structure that will |
| make it possible to access the value given the doc id rapidly. This is useful if the value |
| of the field is required during scoring or collection for instance.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::schema::<span class="kw-2">*</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>schema_builder = Schema::builder(); |
| schema_builder.add_u64_field(<span class="string">"population"</span>, STORED | FAST); |
| schema_builder.add_text_field(<span class="string">"zip_code"</span>, STRING | FAST); |
| <span class="kw">let </span>schema = schema_builder.build();</code></pre></div> |
| </div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.BytesOptions.html" title="tantivy::schema::BytesOptions struct">BytesOptions</a></div><div class="item-right docblock-short">Define how a bytes field should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DateOptions.html" title="tantivy::schema::DateOptions struct">DateOptions</a></div><div class="item-right docblock-short">Defines how DateTime field should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Document.html" title="tantivy::schema::Document struct">Document</a></div><div class="item-right docblock-short">Tantivy’s Document is the object that can |
| be indexed and then searched for.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Facet.html" title="tantivy::schema::Facet struct">Facet</a></div><div class="item-right docblock-short">A Facet represent a point in a given hierarchy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FacetOptions.html" title="tantivy::schema::FacetOptions struct">FacetOptions</a></div><div class="item-right docblock-short">Define how a facet field should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Field.html" title="tantivy::schema::Field struct">Field</a></div><div class="item-right docblock-short"><code>Field</code> is represented by an unsigned 32-bit integer type. |
| The schema holds the mapping between field names and <code>Field</code> objects.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FieldEntry.html" title="tantivy::schema::FieldEntry struct">FieldEntry</a></div><div class="item-right docblock-short">A <code>FieldEntry</code> represents a field and its configuration. |
| <code>Schema</code> are a collection of <code>FieldEntry</code></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FieldValue.html" title="tantivy::schema::FieldValue struct">FieldValue</a></div><div class="item-right docblock-short"><code>FieldValue</code> holds together a <code>Field</code> and its <code>Value</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.IpAddrOptions.html" title="tantivy::schema::IpAddrOptions struct">IpAddrOptions</a></div><div class="item-right docblock-short">Define how an ip field should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.JsonObjectOptions.html" title="tantivy::schema::JsonObjectOptions struct">JsonObjectOptions</a></div><div class="item-right docblock-short">The <code>JsonObjectOptions</code> make it possible to |
| configure how a json object field should be indexed and stored.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.NamedFieldDocument.html" title="tantivy::schema::NamedFieldDocument struct">NamedFieldDocument</a></div><div class="item-right docblock-short">Internal representation of a document used for JSON |
| serialization.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.NumericOptions.html" title="tantivy::schema::NumericOptions struct">NumericOptions</a></div><div class="item-right docblock-short">Define how an <code>u64</code>, <code>i64</code>, or <code>f64</code> field should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Schema.html" title="tantivy::schema::Schema struct">Schema</a></div><div class="item-right docblock-short">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.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SchemaBuilder.html" title="tantivy::schema::SchemaBuilder struct">SchemaBuilder</a></div><div class="item-right docblock-short">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.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Term.html" title="tantivy::schema::Term struct">Term</a></div><div class="item-right docblock-short">Term represents the value that the token can take.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.TextFieldIndexing.html" title="tantivy::schema::TextFieldIndexing struct">TextFieldIndexing</a></div><div class="item-right docblock-short">Configuration defining indexing for a text field.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.TextOptions.html" title="tantivy::schema::TextOptions struct">TextOptions</a></div><div class="item-right docblock-short">Define how a text field should be handled by tantivy.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Cardinality.html" title="tantivy::schema::Cardinality enum">Cardinality</a></div><div class="item-right docblock-short">Express whether a field is single-value or multi-valued.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.DatePrecision.html" title="tantivy::schema::DatePrecision enum">DatePrecision</a></div><div class="item-right docblock-short">DateTime Precision</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.DocParsingError.html" title="tantivy::schema::DocParsingError enum">DocParsingError</a></div><div class="item-right docblock-short">Error that may happen when deserializing |
| a document from JSON.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FacetParseError.html" title="tantivy::schema::FacetParseError enum">FacetParseError</a></div><div class="item-right docblock-short">An error enum for facet parser.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FieldType.html" title="tantivy::schema::FieldType enum">FieldType</a></div><div class="item-right docblock-short">A <code>FieldType</code> describes the type (text, u64) of a field as well as |
| how it should be handled by tantivy.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.IndexRecordOption.html" title="tantivy::schema::IndexRecordOption enum">IndexRecordOption</a></div><div class="item-right docblock-short"><code>IndexRecordOption</code> describes an amount information associated |
| with a given indexed field.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Type.html" title="tantivy::schema::Type enum">Type</a></div><div class="item-right docblock-short">Type of the value that a field can take.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Value.html" title="tantivy::schema::Value enum">Value</a></div><div class="item-right docblock-short">Value represents the value of a any field. |
| It is an enum over all over all of the possible field type.</div></div></div><h2 id="constants" class="small-section-header"><a href="#constants">Constants</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.FAST.html" title="tantivy::schema::FAST constant">FAST</a></div><div class="item-right docblock-short">Flag to mark the field as a fast field (similar to Lucene’s DocValues)</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.INDEXED.html" title="tantivy::schema::INDEXED constant">INDEXED</a></div><div class="item-right docblock-short">Flag to mark the field as indexed. An indexed field is searchable and has a fieldnorm.</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.STORED.html" title="tantivy::schema::STORED constant">STORED</a></div><div class="item-right docblock-short">Flag to mark the field as stored. |
| This flag can apply to any kind of field.</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.STRING.html" title="tantivy::schema::STRING constant">STRING</a></div><div class="item-right docblock-short">The field will be untokenized and indexed.</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.TEXT.html" title="tantivy::schema::TEXT constant">TEXT</a></div><div class="item-right docblock-short">The field will be tokenized and indexed.</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.IntoIpv6Addr.html" title="tantivy::schema::IntoIpv6Addr trait">IntoIpv6Addr</a></div><div class="item-right docblock-short">Trait to convert into an Ipv6Addr.</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.is_valid_field_name.html" title="tantivy::schema::is_valid_field_name fn">is_valid_field_name</a></div><div class="item-right docblock-short">Validator for a potential <code>field_name</code>. |
| Returns true if the name can be use for a field name.</div></div></div><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="type" href="type.IntOptions.html" title="tantivy::schema::IntOptions type">IntOptions</a><span class="stab deprecated" title="">Deprecated</span></div><div class="item-right docblock-short">Deprecated use <a href="struct.NumericOptions.html" title="NumericOptions"><code>NumericOptions</code></a> instead.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tantivy" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |