SearchQL is a search query parser written in Elixir. Given a query such as:
foo AND bar OR "qux AND quux" OR corge AND NOT grault AND garply
SearchQL can generate a data representation of the query:
[or: {
[or: {
[data: "foo", data: "bar"],
[quote: "qux AND quux"]}],
[data: "corge", not: {[data: "grault"]}, data: "garply"]}]
Notice that in the query parsing, AND
binds tighter than OR
, and both
operators are left-associative. This seems to give the best interpretation of
what a human would mean when typing such a query.
A programmer can use SearchQL to determine whether a search query matches a piece of data by providing a module such as SearchQL.StringQuerier that implements the SearchQL.Querier behaviour:
SearchQL.matches?(
~s(foo and bar or baz),
~s(baz),
SearchQL.StringQuerier) # true
For more info, see the SearchQL documentation.
- Add
searchql
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:searchql, "~> 1.0.0"}]
end
```
- Ensure
searchql
is started before your application:
```elixir
def application do
[applications: [:searchql]]
end
```