nseaSeb

nseaSeb

search_ash — multilingual Postgres full-text search for Ash

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.

Where Next?

Popular in Announcing Top

asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ab...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New

Other popular topics Top

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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement