Google Firestore:查询属性值的子字符串(文本搜索) [英] Google Firestore: Query on substring of a property value (text search)
问题描述
我要添加一个简单的搜索字段,想使用类似的
I am looking to add a simple search field, would like to use something like
collectionRef.where('name', 'contains', 'searchTerm')
我尝试使用where('name', '==', '%searchTerm%')
,但没有返回任何内容.
I tried using where('name', '==', '%searchTerm%')
, but it didn't return anything.
推荐答案
没有此类运算符,允许的运算符为==
,<
,<=
,>
,>=
.
There's no such operator, allowed ones are ==
, <
, <=
, >
, >=
.
您只能按前缀过滤,例如,对于可以在bar
和foo
之间开始的所有内容,您都可以使用
You can filter by prefixes only, for example for everything that starts between bar
and foo
you can use
collectionRef.where('name', '>=', 'bar').where('name', '<=', 'foo')
您可以使用外部服务,例如 Algolia 或ElasticSearch.
You can use external service like Algolia or ElasticSearch for that.
这篇关于Google Firestore:查询属性值的子字符串(文本搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!