我希望添加一个简单的搜索字段,想使用类似的东西
collectionRef.where('名称', '包含', 'searchTerm')
我尝试使用 where('name', '==', '%searchTerm%')
,但它没有返回任何内容。
最佳答案
我同意@Kuba的回答,但是,它仍然需要添加一个小更改才能完美地按前缀搜索。这对我有用
用于搜索以名称 queryText
开头的记录
collectionRef
.where('name', '>=', queryText)
.where('name', '<=', queryText+ '\uf8ff')
查询中使用的字符\uf8ff
是Unicode范围内非常高的代码点(它是专用使用区域[PUA]代码)。由于它位于 Unicode 中大多数常规字符之后,因此查询会匹配以 queryText
开头的所有值。
关于firebase - 谷歌Firestore : Query on substring of a property value (text search),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60384903/