gordoneliel

gordoneliel

AshJsonApi: Filter by similiarity

Hi!

I’m trying to filter by similarity eg, name like “eliel” where name could be “Eliel Gordon”.
Is there a way to do this with the filters on ash_json_api or do I have to create my own custom query to handle this?

So far trying filter[name]=eliel only does exact matches

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

What you’d need to do to expose custom filters is to add them as calculations. I realized ash_json_api had no good way to accept calculation inputs, so I’ve added it as an available key when building a filter from input on a field. This is currently on ash main branch. I haven’t documented it, but honestly we need a whole guide on building filters from input. Given a calculation like this:

calculate :name_matches, :boolean, expr(trigram_similarity(name, ^arg(:search)) > 0.7) do
  argument :search, :string, allow_nil? false
end

filter[name_matches][input][search]=foo would do it, which is equivalent to filter[name_matches][input][search]=true&filter[name_matches][eq]=true.

Also Liked

zachdaniel

zachdaniel

Creator of Ash

Calculations will work :slight_smile: However, you may find that you want to create some indexes on things like that.

Last Post!

zachdaniel

zachdaniel

Creator of Ash

Yeah, I think it may have to do with trigram similarity. You may need to use other fragment based full text search tools available in pg

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement