Muninn.Schema (Muninn v0.5.5)
View SourceSchema definition for Muninn search indices.
A schema defines the structure of documents in an index, including field names, types, and indexing options.
Example
schema = Muninn.Schema.new()
|> Muninn.Schema.add_text_field("title", stored: true)
|> Muninn.Schema.add_text_field("body", stored: true)
Summary
Functions
Adds a boolean field to the schema.
Adds a bytes (binary) field to the schema.
Adds a 64-bit floating point field to the schema.
Adds a signed 64-bit integer field to the schema.
Adds a text field to the schema.
Adds an unsigned 64-bit integer field to the schema.
Creates a new empty schema.
Converts the schema to a map representation for NIF consumption.
Validates the schema.
Types
@type t() :: %Muninn.Schema{fields: [Muninn.Schema.Field.t()]}
Functions
Adds a boolean field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field (default:true)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_bool_field(schema, "published", stored: true)
iex> hd(schema.fields).type
:bool
Adds a bytes (binary) field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field (default:true):fast- Whether to enable fast field storage (default:false)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_bytes_field(schema, "payload", stored: true)
iex> hd(schema.fields).type
:bytes
Adds a 64-bit floating point field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field (default:true)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_f64_field(schema, "price", stored: true)
iex> hd(schema.fields).type
:f64
Adds a signed 64-bit integer field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field (default:true)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_i64_field(schema, "temperature", stored: true)
iex> hd(schema.fields).type
:i64
Adds a text field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field for searching (default:true)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_text_field(schema, "title", stored: true)
iex> length(schema.fields)
1
Adds an unsigned 64-bit integer field to the schema.
Options
:stored- Whether to store the field value (default:false):indexed- Whether to index the field (default:true)
Examples
iex> schema = Muninn.Schema.new()
iex> schema = Muninn.Schema.add_u64_field(schema, "count", stored: true)
iex> hd(schema.fields).type
:u64
@spec new() :: t()
Creates a new empty schema.
Examples
iex> schema = Muninn.Schema.new()
iex> schema.fields
[]
Converts the schema to a map representation for NIF consumption.
Examples
iex> schema = Muninn.Schema.new() |> Muninn.Schema.add_text_field("title", stored: true)
iex> map = Muninn.Schema.to_map(schema)
iex> is_map(map)
true
Validates the schema.
Returns :ok if valid, or {:error, reason} if invalid.
Examples
iex> schema = Muninn.Schema.new() |> Muninn.Schema.add_text_field("title")
iex> Muninn.Schema.validate(schema)
:ok
iex> schema = Muninn.Schema.new()
iex> Muninn.Schema.validate(schema)
{:error, :no_fields}