View Source Haystack.Index (Haystack v0.1.0)

A module for managing indexes.

The index is used to manage configuration and acts as a central point to add, update, delete, or query the storage.

Link to this section Summary

Functions

Add documents to the index.

Set the attrs of the index.

Delete documents in the index.

Add a field to the index.

Create a new index.

Add a ref to the index.

Search the index.

Set the storage on the index.

Link to this section Types

@type attrs() :: %{
  insert: [{module(), Keyword.t()}],
  delete: [{module(), Keyword.t()}]
}
@type fields() :: %{required(Haystack.Index.Field.k()) => Haystack.Index.Field.t()}
@type opts() :: Keyword.t()
@type t() :: %Haystack.Index{
  attrs: attrs(),
  fields: fields(),
  name: atom(),
  ref: Haystack.Index.Field.t(),
  storage: struct()
}

Link to this section Functions

@spec add(t(), [map()]) :: t()

Add documents to the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.add(index, [])
@spec attrs(t(), attrs()) :: t()

Set the attrs of the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.attrs(index, %{insert: [Global], delete: [Global]})
@spec delete(t(), [map()]) :: t()

Delete documents in the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.delete(index, [])
@spec field(t(), Haystack.Index.Field.t()) :: t()

Add a field to the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.field(index, Index.Field.new("name"))
@spec new(atom(), opts()) :: t()

Create a new index.

examples

Examples

iex> Index.new(:animals)
@spec ref(t(), Haystack.Index.Field.t()) :: t()

Add a ref to the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.ref(index, Index.Field.new("id"))
Link to this function

search(index, v, opts \\ [])

View Source
@spec search(t(), String.t(), Keyword.t()) :: [map()]

Search the index.

@spec storage(
  t(),
  struct()
) :: t()

Set the storage on the index.

examples

Examples

iex> index = Index.new(:animals)
iex> Index.storage(index, Storage.Map.new())