Home > Back-end >  Ignore Turkish Characters On Firestore Query
Ignore Turkish Characters On Firestore Query

Time:02-23

I have a .net app that uses Firestore as a database and It's using Firestore Query to find some data. The problem is data fields that include Turkish characters but if someone uses my app and wants to search for data and if don't use Turkish characters, the query can not find this data.

For example, if I want to search my name on my app and my name is saved like "Ertuğrul" and if the user searches like "Ertugrul", the query can not find it. I need it to find it. Is there a way to do that?

My code that uses query is here:

QRef = DataBase.Collection("CollName").Document("DocName").Collection("CollName")
                    .WhereGreaterThanOrEqualTo("NameSurname", $"{NameSurname}")
                    .WhereLessThanOrEqualTo("NameSurname", $"{NameSurname}\uF7FF");

CodePudding user response:

Firestore queries always return documents where a particular field holds a perfect match. If you want to be able to search for "Ertuğrul" as well as for "Ertugrul", then besides the "NameSurname" field you should consider adding a new field called "NameSurnameWithoutSpecialCharacters" and store each name without those Turkish characters.

When a user searches, simply verify if the searched term contains "special" characters. If it does, search on the "NameSurname", otherwise search on the newly created field.

  • Related