Firestore database query, ignore case (case insens

2020-07-10 05:31发布

Basically I am writing a search function on a Firestore document field. I want to write equivalent of below SQL. I am not finding solution to proceed.

SELECT * FROM employee WHERE lower(employee_name) LIKE '%johny%';

3条回答
神经病院院长
2楼-- · 2020-07-10 05:55

There is no like operator. See all available operators at: https://firebase.google.com/docs/firestore/query-data/queries The page also contains different ways on querying the database.

For case insensitive sorting / querying please see the answer at Cloud Firestore Case Insensitive Sorting Using Query

It basically advises to store your lowercase data in an additional field.

查看更多
叼着烟拽天下
3楼-- · 2020-07-10 05:59

Cloud Firestore doesn't support native indexing or search for text fields in documents. Additionally, downloading an entire collection to search for fields client-side isn't practical. To enable full text search of your Cloud Firestore data, use a third-party search service like Algolia.

https://firebase.google.com/docs/firestore/solutions/search

查看更多
放荡不羁爱自由
4楼-- · 2020-07-10 06:15

As Norman already wrote, there is no LIKE operator in Firebase.

I wrote an answer in SO that explains how to achieve a similar query (even if it is a StartWith search, rather than a full text search):

databaseReference.orderByChild('_searchLastName')
             .startAt(queryText)
             .endAt(queryText+"\uf8ff")
             .once("value")

If you need more advanced ways of searching, then the advice is to use ElasticSearch, as a possible solution.

查看更多
登录 后发表回答