Full text search

Hi, I've got this calculation and a query that's trying to sort by it
read :full_text_search do
argument :query, :string do
allow_nil? false
description "Search query string"
end

prepare fn query, _ ->
search_query = Ash.Query.get_argument(query, :query)

query
|> Ash.Query.load(search_rank: %{search_query: search_query})
|> Ash.Query.limit(20)
end
end
read :full_text_search do
argument :query, :string do
allow_nil? false
description "Search query string"
end

prepare fn query, _ ->
search_query = Ash.Query.get_argument(query, :query)

query
|> Ash.Query.load(search_rank: %{search_query: search_query})
|> Ash.Query.limit(20)
end
end
calculations do
calculate :search_rank, :float, expr(fragment("ts_rank(?, websearch_to_tsquery('english', ?))", search_vector, ^arg(:search_query))) do
public? true
argument :search_query, :string do
allow_nil? false
end
end
end
calculations do
calculate :search_rank, :float, expr(fragment("ts_rank(?, websearch_to_tsquery('english', ?))", search_vector, ^arg(:search_query))) do
public? true
argument :search_query, :string do
allow_nil? false
end
end
end
but I'm getting this error:
[error] CommandPalette: Search failed: %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidLoad{load: :search_rank, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:load], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
[error] CommandPalette: Search failed: %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidLoad{load: :search_rank, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:load], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
`
4 Replies
theron
theronOP2mo ago
Sorry, this is the way I was loading it: |> Ash.Query.sort([{:search_rank, %{search_query: search_query}, :desc}]) That gives me this fun error:
theron
theronOP2mo ago
theron
theronOP2mo ago
If i change it to
|> Ash.Query.sort(search_rank: {%{search_query: search_query}, :desc})
|> Ash.Query.sort(search_rank: {%{search_query: search_query}, :desc})
i get
[error] CommandPalette: Search failed: %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidLoad{load: :search_rank, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:load], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
[error] CommandPalette: Search failed: %Ash.Error.Invalid{errors: [%Ash.Error.Query.InvalidLoad{load: :search_rank, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:load], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}
making sure it isn't one of the other 4 resources im queryng that's breaking this think i got it working
matt_savvy
matt_savvy5w ago
Hey, looks like you got this working https://blog.1-800-rad-dude.com/posts/2025/08-13-Adding-Postgres-Full-Text-Search-to-an-Ash-Project.html Here's how I added full text search if that helps

Did you find this page helpful?