问题
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