2

I have this search function setup in NestJS using TypeORM:

 public async getAllRecipesBySearchTerm(
    searchTerm: string,
  ): Promise<Recipe[]> {
    return await this.repository.find({
      where: { title: ILike('%' + searchTerm + '%') },
    });
  }

Now when a recipe title contains letters like é or ü they will not be returned. I see that PostgreSQL does support this kind of querying, but does TypeORM support it?

Bowis
  • 541
  • 8
  • 31
  • 1
    I think it doesn't matter if the framework supports accent insensitive or not, it's a feature of your the database you're using. So, you just configure your tables/columns of your database that supports this feature and it will return the results whatever the search term from your queries. Then you can handle on your client app. – Jone Polvora Nov 11 '22 at 13:05
  • 1
    `ILIKE` is case insensitive [`LIKE`](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE) - neither of these ignores diacritics. It will match `searchterm` with `SEARCHTERM`, but not with `séarchterm`. Accent-insensitive regular expressions in PostgreSQL require [extensions or user-defined functions/operators](https://stackoverflow.com/a/11007216/5298879) that you'd have to expose to TypeORM. You could set up an `UILIKE` operator that would apply `unnacent()` and `lower()` to its left and right argument and then look into making it available like `ILIKE` is now. – Zegarek Nov 12 '22 at 09:45

0 Answers0