【问题标题】:Firebase iOS query data with partially matching value [duplicate]具有部分匹配值的 Firebase iOS 查询数据 [重复]
【发布时间】:2016-11-28 08:23:02
【问题描述】:

Firebase queryEqualToValueEQUAL 项返回到指定的键或值。我们如何查询项目PARTIALLY MATCH到指定的键或值?

Firebase iOS retrieve data documentation

【问题讨论】:

  • 正如 iOSGeek 的回答所示,您可以使用 Firebase 进行“开始于”类型的查询。但更广泛的LIKE 搜索是不可能的。见stackoverflow.com/questions/22506531/…
  • @frankvanpuffelen 是的,我想做一个 LIKE 搜索,我已经阅读了博文,但是博文是 2014 年的,所以今天,我仍然没有现成的 firebase 方法或功能用于完成 LIKE 搜索?
  • Firebase 中没有直接的 LIKE 搜索。但是,如果您的数据结构正确,您可以执行Wildcard Searches。这是相似的。
  • 哦,这个问题的答案也适用于 LIKE 类型的搜索。 Real Time Searching

标签: ios swift search firebase firebase-realtime-database


【解决方案1】:

我们可以结合 startAt() 和 endAt() 来限制查询的两端。 以下示例查找名称以 字母“b”:

let ref = Firebase(url:"https://dinosaur-facts.firebaseio.com/dinosaurs")
ref.queryOrderedByKey().queryStartingAtValue("b").queryEndingAtValue("b\u{f8ff}")
   .observeEventType(.ChildAdded, withBlock: { snapshot in

    println(snapshot.key)
})

上面查询中使用的 f8ff 字符是一个非常高的代码点 在 Unicode 范围内。因为它在大多数常规字符之后 Unicode,查询匹配所有以 b 开头的值。

Retrieving Data

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
  • 1970-01-01
  • 2013-08-22
  • 1970-01-01
相关资源
最近更新 更多