nseaSeb

nseaSeb

search_ash — multilingual Postgres full-text search for Ash

Hi everyone,

I’m building a multi-tenant SaaS (Ash + LiveView + Postgres) and needed a global search across several entity types — products, customers, orders… I wanted to avoid pulling in Elasticsearch/Meilisearch just for that, and couldn’t find an existing Ash-native solution, so I built one and open-sourced it.

search_ash v0.1 is a set of Ash extensions for full-text search on top of Postgres tsvector/ts_rank. No hand-written migrations or SQL. It’s built on two other libs I published alongside it: search_core (the non-Ash pipeline logic) and stemmers (a Rust NIF for Snowball stemming, 15+ languages including French).

It covers two use cases:

1. Per-resource search

defmodule MyApp.Post do
  use Ash.Resource,
    domain: MyApp.Blog,
    data_layer: AshPostgres.DataLayer,
    extensions: [SearchAsh]

  postgres do
    table "posts"
    repo MyApp.Repo
  end

  search do
    fields [:title, :body]
    language_attribute :language
  end
end

This generates, at compile time: a :search_text attribute, a change that keeps it in sync on create/update, a GIN expression index (round-trips cleanly with mix ash_postgres.generate_migrations), and a :search read action.

2. Global cross-entity search

This was my actual use case: searching across multiple resource types from one ranked query. SearchAsh.GlobalIndex + SearchAsh.Source maintain a unified index resource, with tenant-aware identities, soft-delete/archive support, and a :global_search action returning ranked, typed results.

Known 0.1 trade-offs (documented in the README, not surprises):

  • Indexing is synchronous (same transaction as the write) — no Oban/async path yet, maybe better to implement the asynch approach in the webapp
  • One language per query (no cross-language OR search)
  • Bulk updates on per-resource search do need strategy: :stream
  • Index creation isn’t CONCURRENTLY yet

There’s a runnable multi-tenant demo in examples/search_demo (Postgres-backed test suite, plus a GreenAsh console for browsing results).

Feedback, issues, and PRs very welcome.

Showing Posts 1 to 8

zachdaniel

zachdaniel

Creator of Ash

Cool :smiling_face_with_sunglasses:

nseaSeb

nseaSeb OP

Thank you, you make my day :wink:

Ash has been a joy to build on top of — this library wouldn’t exist without it. Let me know if anything in the DSL or extension design looks off from an Ash-core perspective, happy to iterate.

kip

kip

ex_cldr Core Team

Nice work.

If you want a pure Elixir snowball-based stemmer then text_stemmer provides the known 35 snowball stemmers and they all pass the conformance tests. It also integrates with localize too.

nseaSeb

nseaSeb OP

@kip Thank you, I’m making the change, sounds good to use it, I agree with U.
And I found an issue with the language, I’m fixing the issue in the same updgrade.

nseaSeb

nseaSeb OP

It’s done v 0.2 published.
Maybe I have to implement the user policies or add an approach to help for the policies, I take a look :thinking:

nseaSeb

nseaSeb OP

The policies are clear-cut: for me, the object type allows for filtering based on permissions, and since we expose the ID, the displayed result can account for those permissions if specific information needs to be hidden. Furthermore, any subsequent access to the object will naturally trigger the web app user’s read/write guards.
I am currently on version 0.3.1 and am evolving it to incorporate reindexing and pruning features tailored to my needs.
Does that sound right?

manhvu

manhvu

Nice job :ok_hand:

nseaSeb

nseaSeb OP

search_ash 0.4.0

Pushed a batch of stuff aimed at making a global search actually easy to wire into a real results page.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New

Other Trending Topics Top

akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews