\ ឵឵឵
\ ឵឵឵
AEAsh Elixir
Created by axdc on 8/31/2023 in #support
st_distance vs <-> in ash_geo for nearest neighbor search/filter (knn)
I like this, because what I really want to say is:
filter expr(not is_nil(location))
sort :distance_from, location: arg(:location)
limit 10
filter expr(not is_nil(location))
sort :distance_from, location: arg(:location)
limit 10
Reading the body of the prepare fn, this seems like it is closest to that.
32 replies
AEAsh Elixir
Created by axdc on 8/31/2023 in #support
st_distance vs <-> in ash_geo for nearest neighbor search/filter (knn)
This part seems fine:
calculate :distance_to, :float, expr(fragment("? <-> ?", location, ^arg(:search_point)))
argument :search_point, App.NarrowedPointType, allow_nil?: false
end
calculate :distance_to, :float, expr(fragment("? <-> ?", location, ^arg(:search_point)))
argument :search_point, App.NarrowedPointType, allow_nil?: false
end
But it looks like the arguments to the calculation in load are statically supplied in the example. The argument is meant to be a geometry (point) supplied as user input. Can load, sort or calculate capture arguments from the action?
32 replies
AEAsh Elixir
Created by axdc on 8/31/2023 in #support
st_distance vs <-> in ash_geo for nearest neighbor search/filter (knn)
Take all of the above with one or two bits of salt, but either way it might be a more maintainable solution for now to do a manual read/modify_query.
32 replies
AEAsh Elixir
Created by axdc on 8/31/2023 in #support
st_distance vs <-> in ash_geo for nearest neighbor search/filter (knn)
For kNN, you definitely want order by ? <-> ?, as the index performance is significantly better. The rest gets a little finnicky: - Currently using this in a sort clause requires that you create an expression-based calculation. - This will need to be a module-based Ash.Calculation, implementing expression/2. - Even module-based calcs only receive the context, but not a changeset, so you would need to use the set_context change builtin. - As far as I know, set_context doesn't support the arg(:?) syntax, but does accept an MFA which will receive the changeset, so you need to provide one that will extract the argument(s) you want. - Your calc module can then use these to build the expression, which you can then sort on.
32 replies
AEAsh Elixir
Created by jart on 8/23/2023 in #support
Postgrex error when creating record with AshGeo type
Yeah tbh I was wondering 😄
12 replies