How to search in Firestore database?

243

When you are using the following call:

.where('name', isGreaterThanOrEqualTo: customer)

It means that you are searching the database for the documents in which the "name" property holds a value that is greater than the one you are typing. In this particular case, both "Omar" and "Second Omar" are present in the result-set, since each one of them starts with a letter that is alphabetically ordered after "k". In fact, all capital letters are present in alphabetical order after the lower-case letters. Remember that the search is performed lexicographically.

If you are looking for a full-text search, please note that Firestore doesn't provide one. As @Dharmaraj mentioned in his comment, you should use a third-party solution. You can also find more info in my answer from the following posts:

Share:
243
Omar Abdelazeem
Author by

Omar Abdelazeem

Updated on December 31, 2022

Comments

  • Omar Abdelazeem
    Omar Abdelazeem over 1 year

    I am using this way to search for users in firestore database and I think that it is inefficient way , because it give unrelated results , for example if I type 'k' it give me results does not contain 'k' at all like the image below .

     var query = firestore
        .collection("users")
        .where('name', isGreaterThanOrEqualTo: customer)
        .get()
        .asStream();
    

    enter image description here

    any suggestion please ?!

    • Dharmaraj
      Dharmaraj almost 3 years
      Firestore doesn't have any native full text search feature that you are looking for. You'll have to use 3rd party service like Algolia or store an array like ["o", "om", "oma", "omar"] so you can use array-contains operator. Oh and O is greater than K You can read more about that in String comparison