prisma icon indicating copy to clipboard operation
prisma copied to clipboard

Add accent insensitive query mode

Open friebetill opened this issue 3 years ago • 13 comments

Problem

Currently there is a possibility to search a database case insensitive with QueryMode.insensitive. I would like to additionally search the database accent insensitive.

Suggested solution

Extend the QueryMode.insensitive to be also accent insensitive or add the QueryMode.accentInsensitive with the possibility to combine the mode with QueryMode.insensitive (it would probably be good to rename QueryMode.insensitive to QueryMode.caseInsensitive)

friebetill avatar Apr 06 '21 13:04 friebetill

Hey @friebetill, I can understand the use case. This is unfortunately a very complex subject and our current implementation is best-effort and depends on a lot of factors.

Do you know how you would do this in SQL? If we have the SQL and potentially database collation settings, we can have a closer look.

matthewmueller avatar Apr 14 '21 15:04 matthewmueller

Thanks for your answer! So far I haven't implemented anything, but I will probably follow this Stack Overflow answer and use the extension unaccent to solve it. I hope that this extension can be installed directly in Postgres and then used with the Prisma client via $queryRaw.

Of course, the approach does not work for the other databases and the first search result, e.g. for MySQL is not promising.

friebetill avatar Apr 15 '21 09:04 friebetill

@friebetill If you've had any success with installing the module and using the function in a $rawQuery (and still have access to it, because it's been a while since you posted), please share here because I'm racking my brains to find out how to implement this :)

theduardomaciel avatar Apr 10 '22 15:04 theduardomaciel

Unfortunately, I didn't have and still don't have the time to investigate it further.

friebetill avatar May 22 '22 06:05 friebetill

Any updates ?

sostenesapollo avatar Nov 09 '22 19:11 sostenesapollo

It will be very helpful to get "unaccent" from postgreSQL working without having to use query raw

Ben212 avatar Jan 25 '23 13:01 Ben212

Yes same thing, the whole search and fulltextsearch features of prisma become kinda useless at the moment you have non ASCII characters contents. When you have multi language contents (japanese, chinese, ...) It become impossible to do a decent db search with default prisma tools and casing.

It's frustrating to rely on raw query just to wrap the field you search or filter with lower(unaccent(title)).

kefniark avatar Feb 10 '23 01:02 kefniark

Any news on this Unaccent use case?

andrefelipeschulle avatar May 24 '23 02:05 andrefelipeschulle

To be able to use "unnacent" with a complex/typesafe "where", I'm using 2 queries:

  1. The first using "queryRawUnsafe" that returning IDs
  2. The second using these IDs to compose a native Prisma query.

Hope it helps someone :) Does anyone have a better approach?

Example

Cauen avatar Sep 22 '23 20:09 Cauen

Accent insensitive search is very important for languages like Portuguese and others.

When trying to search "João" people may use "joao" and this should be handled by prisma to avoid doing a lot of raw queries to make that work!

luizfelipelaviola avatar Oct 26 '23 00:10 luizfelipelaviola

Any news about this?

lmalvasia avatar Mar 12 '24 01:03 lmalvasia

Hey @friebetill, I can understand the use case. This is unfortunately a very complex subject and our current implementation is best-effort and depends on a lot of factors.

Do you know how you would do this in SQL? If we have the SQL and potentially database collation settings, we can have a closer look.

Hello there, I'm also in need of searching without having to think about accent.

Unfortunatly, I didn't have the chance yet to deep dive into the code of Prisma. So maybe what I am about to say is retarded :)

If it's complicated to handle it for all languages, maybe we could settle for a solution where Prisma provides a hook called when the unaccent parameter is set? The objective of this function would be to locally modify the query and apply PSQL functions like unaccent ? For example ("lastname = 'BRËS'") => ("unaccent(lastname)= unaccent('BRËS')")

It would prevent the use of raw query for the time being, and once the feature is fully operational, the hook can be ignored.

gandrin avatar May 02 '24 10:05 gandrin

Ahhhh, remembering how I love modern ORMs... "Prisma is a next-generation Node.js and TypeScript ORM that unlocks a new level of developer experience"

vanflux avatar May 17 '24 17:05 vanflux