【问题标题】:How to search substring using firestore query in firestore document's field? [duplicate]如何在firestore文档的字段中使用firestore查询搜索子字符串? [复制]
【发布时间】:2018-10-19 12:06:48
【问题描述】:

Android/Java:

在 Firestore 文档中,我有一个字段“名称”,其值为 America

我想创建一个 firebase 查询,如果我在其中传递 ame,那么它确实会返回名称字段中包含 ame 的所有文档。

firebaseFirestore.collection("country").whereContains("name", "ame");

简而言之,我想使用子字符串搜索/过滤 Firestore 数据。

【问题讨论】:

标签: java android firebase google-cloud-firestore


【解决方案1】:

为此,有一些“可能”的帮助,它被称为array-contains 查询。在这里了解更多信息,https://firebase.googleblog.com/2018/08/better-arrays-in-cloud-firestore.html

它的使用方式如下:

collection("collectionPath").
    where("searchTermsArray", "array-contains", "term").get()

否则,您还可以选择使用外部服务,例如 Algolia 或 ElasticSearch。

【讨论】:

  • firestore 不再支持 where in java 了。我的字段数据类型是字符串而不是数组。
  • 您可以将其设为数组或使用答案中所述的 Algolia。
猜你喜欢
  • 2018-04-03
  • 1970-01-01
  • 2018-12-14
  • 2020-07-24
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 2020-08-12
相关资源
最近更新 更多