Ash FrameworkAF
Ash Framework3mo ago
10 replies
theron

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

  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}]}
`
Was this page helpful?