Class SchemaBuilder
- Namespace
- TantivyDotNet
- Assembly
- TantivyDotNet.dll
Fluent builder for a Schema.
public sealed class SchemaBuilder
- Inheritance
-
SchemaBuilder
- Inherited Members
Examples
var schema = new SchemaBuilder()
.AddTextField("title", stored: true)
.AddStringField("id", stored: true)
.AddU64Field("year", fast: true)
.Build();
Methods
- AddAnalyzer(string, Analyzer)
Registers a custom
analyzerundername, for use as thetokenizerof text fields. The definition is part of the schema: an index created in a directory saves it, and Open(string) restores it.
- AddBoolField(string, bool, bool, bool)
Adds a boolean field.
- AddBytesField(string, bool, bool, bool)
Adds a bytes field. In JSON documents, values are base64 strings.
- AddDateField(string, bool, bool, bool)
Adds a date field. In JSON documents, dates are RFC 3339 strings with an offset (for example
2024-05-01T12:00:00Z); use DateTimeOffset or UTC DateTime values when adding objects. Precision is seconds.
- AddF64Field(string, bool, bool, bool)
Adds a 64-bit floating-point field.
- AddFacetField(string, bool)
Adds a facet field: hierarchical category paths like
/genre/fiction/classic, used for filtering (Facet(string, string)) and counting (FacetRequest). In JSON documents a value is a path string, or an array of them for several categories. Paths start with/; a/inside a segment is escaped as/. Facet fields are always indexed and fast.
- AddI64Field(string, bool, bool, bool)
Adds a signed 64-bit integer field.
- AddIpAddressField(string, bool, bool, bool)
Adds an IP address field. In JSON documents, values are strings like
192.168.0.1or2001:db8::1; IPv4 addresses are stored as IPv4-mapped IPv6 and returned as IPv4. Query with Term(string, IPAddress) and ranges.
- AddJsonField(string, bool, bool, string)
Adds a JSON field: each document can put any JSON object in it, without declaring the keys. Query a key by its path:
Query.Term("attrs.color", "red"),Query.Range("attrs.size", 2L, 5L), orattrs.color:redin parsed queries. Strings are tokenized withtokenizer; numbers, booleans and RFC 3339 dates keep their type.
- AddStringField(string, bool, bool)
Adds an untokenized text field: the whole value is a single term. Use it for identifiers, tags and enum-like values that you match exactly or delete by (DeleteTerm(string, string)).
- AddTextField(string, bool, bool, string)
Adds a full-text field. Its values are split into terms by
tokenizer(defaultsplits on whitespace and punctuation, lowercases, and drops very long tokens;en_stemalso applies English stemming;rawkeeps the whole value as one term).
- AddU64Field(string, bool, bool, bool)
Adds an unsigned 64-bit integer field.
- Build()
Creates the schema. The builder can keep being used afterwards.