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
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
Calculations will work
However, you may find that you want to create some indexes on things like that.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








