Rumamge.Ecto v0.1.1 Rummage.Ecto.Hooks.Search
Rummage.Ecto.Hooks.Search is the default search hook that comes shipped
with Rummage.
This module can be overridden with a custom module while using Rummage.Ecto
in Ecto struct module.
Summary
Functions
Builds a search query on top of the given query from the rummage parameters
from the given rummage struct
Functions
Builds a search query on top of the given query from the rummage parameters
from the given rummage struct.
Examples
When rummage struct passed doesn’t have the key “search”, it simply returns the query itself:
iex> alias Rummage.Ecto.Hooks.Search
iex> import Ecto.Query
iex> Search.run(Parent, %{})
Parent
When the query passed is not just a struct:
iex> alias Rummage.Ecto.Hooks.Search
iex> import Ecto.Query
iex> query = from u in "parents"
#Ecto.Query<from p in "parents">
iex> Search.run(query, %{})
#Ecto.Query<from p in "parents">
When rummage struct passed has the key “search”, with “field” and “term” it returns a searched version of the query passed in as the argument:
iex> alias Rummage.Ecto.Hooks.Search
iex> import Ecto.Query
iex> rummage = %{"search" => %{"field_1" => "field_!"}}
%{"search" => %{"field_1" => "field_!"}}
iex> query = from u in "parents"
#Ecto.Query<from p in "parents">
iex> Search.run(query, rummage)
#Ecto.Query<from p in "parents", where: like(p.field_1, ^"%field_!%")>