I’m trying to dynamically define the language I want for my PostgreSQL full text search:
def search(query, search_term, locale) do
language =
case locale do
"pt" ->
"portuguese"
"es" ->
"spanish"
"fr" ->
"french"
"de" ->
"german"
_ ->
"english"
end
(from u in query,
where: fragment("(to_tsvector(?, unaccent(?)) || to_tsvector(?, unaccent(?)) || to_tsvector(coalesce(?, unaccent(?)))) @@ plainto_tsquery(?, unaccent(?))",
^language, u.date, ^language, u.title, ^language, u.text, ^language, ^search_term),
order_by: fragment("ts_rank((to_tsvector(?, ?) || to_tsvector(?, ?) || to_tsvector(coalesce(?, ?))), plainto_tsquery(?, ?)) DESC",
^language, u.date, ^language, u.title, ^language, u.text, ^language, ^search_term))
|> Repo.all()
end
But, I’m getting this error:
(RuntimeError) type
regconfigcan not be handled by the types module Ecto.Adapters.Postgres.TypeModule
The code works fine when I place the language directly, i.e.:
to_tsvector('portuguese', unaccent(?)) || ...
After trying to understand what this PostgreSQL type (regconfig
) is and a few more tests I’m convinced that it could be due too the fact of using ''
to define the language name instead of using ""
but I’ve tried sigils and also explicitly passing the ^language
type with no success, so I imagine that this must be some very Ecto specific issue.