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.
Evaluate a clause.
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
@spec build(atom(), Haystack.Index.t(), [Haystack.Tokenizer.Token.t()]) :: Haystack.Query.Clause.t()
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.
@spec evaluate(t(), Haystack.Index.t(), Haystack.Query.Expression.t()) :: [map()]
Evaluate an expression.
@spec evaluate(t(), Haystack.Index.t(), Haystack.Query.Clause.t(), [statement()]) :: [ map() ]
Evaluate a clause.
Create a new Query.
@spec run(t(), Haystack.Index.t()) :: [map()]
Run the given query.