Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search in Firestore database?

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 ?!

like image 350
Omar Abdelazeem Avatar asked Sep 05 '25 23:09

Omar Abdelazeem


1 Answers

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:

  • Search by pattern on Cloud Firestore collection

  • Is it possible to use Algolia query in FirestoreRecyclerOptions?

like image 76
Alex Mamo Avatar answered Sep 08 '25 23:09

Alex Mamo