ecto_searcher v0.1.0 EctoSearcher.Searcher View Source
Module for searching
Usage
searhable_fields = [:name, :description]
search = %{"name_eq" => "Donald Trump", "description_cont" => "My president"}
query = EctoSearcher.Searcher.search(MyMegaModel, search, searchable_fields)
MySuperApp.Repo.all(query)
Link to this section Summary
Link to this section Functions
Link to this function
search(schema, search_params, searchable_fields, mapping \\ EctoSearcher.Searcher.DefaultMapping)
View Source
Shortcut for search/5
Takes schema
as base_query
and optional mapping
(defaults to EctoSearcher.Searcher.DefaultMapping
).
Link to this function
search(base_query, schema, search_params, searchable_fields, mapping)
View Source
Builds search query
Takes %Ecto.Query{}
as base_query
and ecto model as schema
.
search_params
should be a map with search_fields in form of "field_condition"
like this:
%{
"name_eq" => "Donald Trump",
"description_cont" => "My president"
}
searchable_fields
should be a list of field names as atoms (looked up from schema or from mapping.fields
):
[:name, :description]
mapping
should implement EctoSearcher.Searcher.Mapping
behavior. EctoSearcher.Searcher.DefaultMapping
provides some basics.