Sifter is a a query filtering library for Ecto.
It lets frontend apps send human-readable query strings like:
"elixir phoenix status:published OR (draft author:me) createdAt:>=2024-01-01"
and turns them into safe, validated Ecto queries with full-text search support.
Key Features
- Rich query syntax: field predicates, boolean logic, IN/NOT IN, wildcards, lists.
- Full-text search: supports
:ilikeor PostgreSQLtsquery. - Field allow-lists: keep filtering secure with schema-aware whitelisting.
- Friendly errors: lexer/parser messages with positions.
- SQL inspection:
Sifter.to_sql/4for debugging and testing.
Example
{query, meta} = Sifter.filter!(Post, params["q"],
schema: Post,
allowed_fields: ["status", "priority", "author.name"],
search_fields: ["title", "content"],
search_strategy: {:tsquery, "english"}
)
posts = Repo.all(query)
IO.inspect(meta)
# %{uses_full_text?: true, recommended_order: [search_rank: :desc]}
GitHub Repo:






















