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

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

问题描述

我对Firebase查询有点麻烦。我想查询对象,其中对象的子值包含一定的字符串。到目前为止我有这样的东西:

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

但是只有初始值为b的对象。我想要包含字符串b的对象。

解决方案

在查询API中没有包含或模糊匹配的方法,你可能已经猜到了如果您已扫描 API 查询指南



不仅对此主题进行了讨论,对SO [ 1 ] [ 2 ] [< a href =http://stackoverflow.com/questions/10559191/firebase-and-indexing-search> 3 ] [ 4 ] [ 5 ],但我已经碰了几次为什么应该使用真实的搜索引擎,而不是尝试这种半心半意的搜索方法。



有一个原因,Google网站查找结果通常比使用内置搜索更容易,这是该失败的主要组成部分。 p>

所有这一切,你的问题的答案如何手动,因为没有内置的包含,是设置一个服务器端进程加载/流数据到存储器中并且手动搜索内容,优选地利用某种高速缓存。



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


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);
}];

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?

解决方案

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.

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.

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.

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.

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天全站免登陆