AshScylla.Search.Query.Parser (AshScylla v1.6.1)

Copy Markdown View Source

Parses user search queries.

Handles:

  • Simple word queries: learning phoenix
  • AND queries: learning AND phoenix or implicit AND between words
  • OR queries: learning OR phoenix
  • NOT queries: phoenix NOT framework
  • Phrase queries: "phoenix framework" (V2)

Returns a parsed query structure representing the boolean logic.

Summary

Functions

Parses a query string into a structured representation.

Types

ast_node()

@type ast_node() ::
  AshScylla.Search.Query.Parser.Term.t()
  | AshScylla.Search.Query.Parser.Phrase.t()
  | AshScylla.Search.Query.Parser.Group.t()
  | AshScylla.Search.Query.Parser.NotExpr.t()

Functions

parse(query)

@spec parse(String.t()) :: {:ok, ast_node()} | {:error, term()}

Parses a query string into a structured representation.

Examples

iex> Parser.parse("learning phoenix")
{:ok, %Group{terms: [%Term{word: "learning"}, %Term{word: "phoenix"}], op: :and}}

iex> Parser.parse("elixir OR phoenix")
{:ok, %Group{terms: [%Term{word: "elixir"}, %Term{word: "phoenix"}], op: :or}}

iex> Parser.parse("phoenix NOT framework")
{:ok, %Group{terms: [%Term{word: "phoenix"}, %NotExpr{term: %Term{word: "framework"}}], op: :and}}

parse!(query)

@spec parse!(String.t()) :: ast_node()