是否可以查询Firestore文档中的多个字段以获取相同的值?
想象一下,我有许多文件描述了一项运动:
sportsRef.collection("sports").documents [
["bowling" : [
"equipment": "bowling ball, bowling alley, bowling shoes",
"description": "bowl the ball" ]]
["football": [
"equipment": "ball, boots, shin pads, goalie gloves",
"description": "kick the ball in the goal" ]]
["darts": [
"equipment": "darts, dartboard",
"description": "throw the dart at the board" ]]
["boxing": [
"equipment": "boxing gloves, ring",
"description": "punch your contender" ]]
["shot put": [
"equipment": "shot put",
"description": "throw the shot put, looks like a ball" ]]
]
有没有一种查询方法,如果我搜索“ ball”的值,将返回其值内包含“ ball”的所有文档。因此,在这种情况下,我将得到保龄球,足球和铅球(在铅球的描述中为“球”)。
我之所以这样问,是因为我已经在iOS应用中实现了UISearchController,并想通过在应用中构造查询来在Firestore中进行搜索。
Firestore不支持查询的子串,正则表达式或全文搜索类型。这类搜索无法随Firestore管理索引的方式扩展。
如果需要全文搜索,请考虑将数据复制到诸如Algolia的搜索引擎中。Firebase文档中讨论了这种解决方案。