How can I do a 'like' query or similarity search?
Hi,
I am looking to do fuzzy search. So, for example , if the user types in 'dan'. I'd like to return all users whose names or emails include 'dan'. I read through the predicate list here: https://hexdocs.pm/ash/Ash.Filter.html hoping for something like 'like' in SQL, but I didnt see naything. What is the best approach?
Here is how my code looks currently:
App.EmailHandler.User
|> Ash.Query.filter(
[or: [
[email: search_slug],
[name: search_slug]
]])
6 Replies
You could use an expression for this:
(this assumes you're using
ash_postgres
as your datalayer)like
and ilike
are provided by the ash_postgres
data layerYou can also use the builtin
contains
function
ash_hq also has search built upon postgres full text search depending on your needs. This transformer adds the necessary search stuff to the resource, I used as a reference to implement search in my own application
GitHub
ash_hq/lib/ash_hq/docs/extensions/search/transformers/add_search_st...
The Ash Framework homepage and documentation site. - ash-project/ash_hq