Firebase“Where”像搜索 [英] Firebase "Where" like search

查看:137
本文介绍了Firebase“Where”像搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Firebase中的Where风格得到一个简单的结果,但获得空时间,任何人都可以帮助吗?



http://jsfiddle.net/vQEmt/68/

 新的Firebase(https://examples-sql-queries.firebaseio.com/messages)
.startAt('Inigo Montoya')
.endAt('Inigo Montoya ')
.once('value',show);

function show(snap){
$('pre')。text(JSON.stringify(snap.val(),null,2));


解决方案

查看适用的记录,我发现 .priority 被设置为时间戳,而不是用户名。



因此,您不能像这里尝试的那样启动/结束用户的名字。这些只适用于.priority字段。随着Firebase API的增强功能不断推出,这些功能将在明年大幅扩展。

现在,您可以使用任意搜索字段的最佳选择一个搜索引擎。这很容易让一个人旋转起来,并在搜索引擎的全部力量在你的指尖,而不是用冰河SQL式esque查询mucking。看起来你已经偶然发现了相应的博客当然,你可以使用一个按名字列出用户的索引,并存储他们所有后期标识符的键值。而且,考虑到这是一个非常小的数据集(小于100k),甚至可以抓住整个事物并在客户端上搜索它(更大的数据集可以使用endAt / startAt / limit来获取最近的消息子集):

 新的Firebase(https://examples-sql-queries.firebaseio.com/messages).once('value ',function(snapshot){
var messages = [];
snapshot.forEach(function(ss){
if(ss.val()。name ===Inigo Montoya ){
messages.push(ss.val());
}
});
console.log(messages);
});

另见:


Tryng to get a simple result using "Where" style in firebase but get null althe time, anyone can help with that?

http://jsfiddle.net/vQEmt/68/

new Firebase("https://examples-sql-queries.firebaseio.com/messages")
.startAt('Inigo Montoya')
.endAt('Inigo Montoya')
.once('value', show);

function show(snap) {
   $('pre').text(JSON.stringify(snap.val(), null, 2));
}

解决方案

Looking at the applicable records, I see that the .priority is set to the timestamp, not the username.

Thus, you can't startAt/endAt the user's name as you've attempted here. Those are only applicable to the .priority field. These capabilities will be expanding significantly over the next year, as enhancements to the Firebase API continue to roll out.

For now, your best option for arbitrary search of fields is use a search engine. It's wicked-easy to spin one up and have the full power of a search engine at your fingertips, rather than mucking with glacial SQL-esque queries. It looks like you've already stumbled on the appropriate blog posts for that topic.

You can, of course, use an index which lists users by name and stores the keys of all their post ids. And, considering this is a very small data set--less than 100k--could even just grab the whole thing and search it on the client (larger data sets could use endAt/startAt/limit to grab a recent subset of messages):

new Firebase("https://examples-sql-queries.firebaseio.com/messages").once('value', function(snapshot) {
   var messages = [];
   snapshot.forEach(function(ss) {
      if( ss.val().name === "Inigo Montoya" ) {
         messages.push(ss.val());
      }
   });
   console.log(messages);
});

Also see: Database-style queries with Firebase

这篇关于Firebase“Where”像搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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