rodloboz

rodloboz

Sifter - a flexible string-based query filtering library for Ecto

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 :ilike or PostgreSQL tsquery.
  • Field allow-lists: keep filtering secure with schema-aware whitelisting.
  • Friendly errors: lexer/parser messages with positions.
  • SQL inspection: Sifter.to_sql/4 for 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:

Most Liked

rodloboz

rodloboz

Hi, thanks!

The grammar for the query is captured in the Lexer docs:

As for wether it is used elsewhere, I don’t think so. I implemented something similar in a previous job and at that time I drew heavily from Shopify’s search query sintax: Shopify API search syntax

So that’s likely the closest to this format that’s in use out there :slight_smile:

Where Next?

Popular in Announcing Top

metehan
ExTerm is a minimal Elixir library that lets you expose your terminal in a web browser. It’s mostly a toy project for learning and experi...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API. Docs are at OpenaiEx User Guide — ope...
New
kasvith
Hello Everyone, I was working with some HTML-to-Markdown libraries and ran into a few issues when converting a complex markup file to Ma...
New
rahultumpala
Hello Elixir community, I work primarily on Java and other object oriented programming languages and often found it difficult to read an...
New
lucaong
CubDB is an embedded database written in pure Elixir, designed for robustness and minimal use of resources. It strives to be as developer...
New
bradley
I’ve been working with Claude Code extensively and absolutely love it. However, I’ve come across the challenge of managing configuration ...
New
garrison
Hobbes is a scalable, fault-tolerant transactional record store written in Elixir. Hobbes is designed to be: Scalable - Hobbes can sha...
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
LostKobrakai
I’ve recently created a small library phoenix_vite integrating the vite build tooling with phoenix. It provides an igniter.installer t...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement