Firestore database query, ignore case (case insenstive) and like clause.

六月ゝ 毕业季﹏ 提交于 2020-06-10 15:23:28

问题


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%';


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/50005587/firestore-database-query-ignore-case-case-insenstive-and-like-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!