2

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
  • 47,845
  • 8
  • 52
  • 84
Omar Abdelazeem
  • 381
  • 2
  • 20
  • 1
    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](https://jsfiddle.net/7hpebd4z/) You can read more about that in [String comparison](https://javascript.info/comparison) – Dharmaraj Jul 29 '21 at 15:22

1 Answers1

4

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:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193