跨多个字段的Firestore查询值相同 [英] Firestore Query Across Multiple Fields for Same Value

查看:58
本文介绍了跨多个字段的Firestore查询值相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查询Firestore文档中的多个字段以获取相同的值?

Is it possible to query multiple fields in a firestore document for the same value?

想象一下,我有许多文件描述了一项运动:

Imagine I have numerous documents where each described a sport:

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"的所有文档.因此,在这种情况下,我将得到保龄球,足球和铅球(在铅球的描述中为球").

Is there any way to make a query that, if I searched for a value of "ball", would return all the documents that have "ball" within their values. So in this case I would be returned bowling, football and shot put ("ball" is in the description of shot put).

之所以问,是因为我在iOS应用中实现了UISearchController,并试图通过在应用中构造查询来在Firestore中进行搜索.

The reason why I ask is because I have implemented a UISearchController in my iOS app and am trying to do the search in my Firestore by constructing a query in my app.

推荐答案

Firestore不支持查询的子字符串,正则表达式或全文搜索类型.这类搜索无法满足Firestore管理索引的方式.

Firestore doesn't support substring, regular expression, or full text search types of queries. Those kind of searches don't scale with the way Firestore manages its indexes.

如果您需要全文搜索,请考虑将数据复制到诸如Algolia的搜索引擎中.此类解决方案是在Firebase文档中讨论的.

If you need fully text searching, consider duplicating your data into a search engine such as Algolia. This type of solution is discussed in the Firebase docs.

这篇关于跨多个字段的Firestore查询值相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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