简体   繁体   中英

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();

在此处输入图片说明

any suggestion please ?!

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM