Firebase 查询 - 查找包含字符串的子项 [英] Firebase query - Find item with child that contains string

查看:25
本文介绍了Firebase 查询 - 查找包含字符串的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Firebase 查询时遇到了一些麻烦.我想查询对象,其中对象的子值包含某个字符串.到目前为止,我有一些看起来像这样的东西:

I'm having a bit of trouble with a Firebase Query. I want to query for objects, where the objects child value contains a certain string. So far I have something that looks like this:

Firebase *ref = [[Firebase alloc] initWithUrl:@"https://dinosaur-facts.firebaseio.com/dinosaurs"];
[[[[ref queryOrderedByKey] queryStartingAtValue:@"b"] queryEndingAtValue:@"b~"]
    observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
    NSLog(@"%@", snapshot.key);
}];

但这只会给出起始值为b"的对象.我想要包含字符串b"的对象.我该怎么做?

But that only gives objects that have a starting value of "b". I want objects that contains the string "b". How do I do that?

推荐答案

查询 API 中没有包含或模糊匹配的方法,如果您浏览过API查询指南.

There are no contains or fuzzy matching methods in the query API, which you have probably already guessed if you've scanned the API and the guide on queries.

不仅在 SO [1] [2][3] [4] [5],但我已经多次提到为什么应该使用真正的搜索引擎,而不是尝试这种半心半意的搜索方法.

Not only has this subject been discussed ad nauseam on SO [1] [2] [3] [4] [5], but I've touched several times on why one should use a real search engine, instead of attempting this sort of half-hearted search approach.

通过 Google 搜索网站通常比使用内置搜索更容易找到结果是有原因的,这是导致失败的主要因素.

There is a reason it's often easier to Google a website to find results than to use the built-in search, and this is a primary component of that failure.

综上所述,由于没有内置 contains,您如何手动执行此操作的问题的答案是设置一个服务器端进程,将数据加载/流式传输到内存中并进行手动搜索的内容,最好有某种缓存.

With all of that said, the answer to your question of how to do this manually, since there is no built-in contains, is to set up a server-side process that loads/streams data into memory and does manual searching of the contents, preferably with some sort of caching.

但老实说,ElasticSearch 在这里更快、更简单,也更高效.由于这是一个很大的话题,我将推迟到 关于此主题的博文.

But honestly, ElasticSearch is faster and simpler, and more efficient here. Since that's a vast topic, I'll defer you to the blog post on this subject.

这篇关于Firebase 查询 - 查找包含字符串的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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