View Source Haystack.Query (Haystack v0.1.0)

A module for building queries.

Link to this section Summary

Functions

Build a clause for the given list of tokens.

Add a clause to the query.

Evaluate an expression.

Create a new Query.

Run the given query.

Link to this section Types

@type statement() :: (t(), Haystack.Index.t() -> [map()])
@type t() :: %Haystack.Query{
  clause: Haystack.Query.Clause.t(),
  config: Keyword.t(),
  index: term()
}

Link to this section Functions

Link to this function

build(atom, index, tokens)

View Source

Build a clause for the given list of tokens.

examples

Examples

iex> index = Index.new(:animals)
iex> index = Index.field(index, Index.Field.new("name"))
iex> tokens = Tokenizer.tokenize("Red Panda")
iex> tokens = Transformer.pipeline(tokens, Transformer.default())
iex> Query.build(:match_all, index, tokens)
@spec clause(t(), Haystack.Query.Clause.t()) :: t()

Add a clause to the query.

Link to this function

evaluate(query, index, expression)

View Source
@spec evaluate(t(), Haystack.Index.t(), Haystack.Query.Expression.t()) :: [map()]

Evaluate an expression.

Link to this function

evaluate(query, index, clause, statements)

View Source
@spec evaluate(t(), Haystack.Index.t(), Haystack.Query.Clause.t(), [statement()]) :: [
  map()
]

Evaluate a clause.

@spec new(Keyword.t()) :: t()

Create a new Query.

@spec run(t(), Haystack.Index.t()) :: [map()]

Run the given query.