Accent-insensitive queries with Postgres #17628
Closed
juanpablob
started this conversation in
General
Replies: 1 comment 2 replies
|
Thanks for raising this. Today, the Postgres adapter can install the unaccent extension, but Payload does not use it when building contains or like queries. This could allow a simple built-in preset: postgresAdapter({
extensions: ['unaccent'],
query: {
operatorHandlers: [postgresUnaccent()],
},
})The same API could also support custom SQL functions or different extensions without requiring duplicate normalized fields. We would need to cover contains, like, and not_like, as well as consider JSON/rich-text queries and indexing performance. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi Payload team,
I’m looking for guidance around accent-insensitive search when using Payload with the Postgres adapter.
We have user-generated content in multiple languages, so some searchable fields contain accents or diacritics, for example:
ÁcidoÄpfelCaféNiñoMünchenIn the UI, we expose searchable selects / comboboxes where users often type plain input like:
acidoapfelcafeninomunchenThe problem is that a query like this:
does not match a stored value like
Ácido.From what I understand, Payload/Postgres text filtering is accent-sensitive by default, and one workaround suggested out there was to duplicate fields into normalized versions, for example:
and then query
normalizedTitle.But for our use case this is not really sustainable, because we would need to duplicate many searchable fields across collections, hooks, nested fields, localized content, tags, etc. It also means every search UI needs to know which normalized field to query.
I've also read about Postgres
unaccent, but since Payload builds the SQL internally, I’m not sure if there is a clean way to use it for normal where queries. I also saw collation-based approaches, but I'm not sure whether those work correctly with contains / like queries or what side effects they may have.So my questions are:
Thank you!
Best,
Juampi
All reactions