Google Firestore:查询属性值的子字符串(文本搜索) [英] Google Firestore: Query on substring of a property value (text search)

查看:65
本文介绍了Google Firestore:查询属性值的子字符串(文本搜索)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加一个简单的搜索字段,想使用类似的

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 ==, <, <=, >, >=.

您只能按前缀过滤,例如,对于可以在barfoo之间开始的所有内容,您都可以使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆