使用Firebase过滤搜索? [英] Filtered searches with Firebase?

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

问题描述

我正在寻找一个搜索栏,用户可以通过Firebase上的用户进行搜索,并在键入的时候更新桌面视图,而不仅仅是搜索完全匹配的内容。

  func searchBar(searchBar:UISearchBar,textDidChange searchText:String){
if searchBar.text == nil || searchBar.text =={
inSearchMode = false
tableView.reloadData()
} else {
inSearchMode = true
let lower = searchBar.text !. lowercaseString

filteredPeopleArray = peopleArray.filter({$ 0.title.hasPrefix(lower)!= nil})
tableView.reloadData()
}

这段代码适用于这种情况,但是这需要在负载中为我填充当前在firebase上的每个用户的数组在应用程序打开的过程中不断追加新用户。



我发现解析过程中有一个find users where key contains string和你会做一个查询解析你的textDidChange,但我没有看到任何类似的Firebase。另外,如果每次输入一个字母的时候,都不会以任何方式向数据库发送数据。

像Instagram一样使用什么方法你在哪里键入一些字母,并返回一个服务器的用户名单中的名称前缀?所以像博可能会返回一个鲍勃和bobbys列表。

解决方案

我无法评论,但是这里有一篇帮助我的文章。 $ b

https: //www.quora.com/How-would-you-search-a-Firebase-Realtime-Database-with-a-substring



说吧你有下面的firebase数据

  {
lambeosaurus:{
dimensions:{
height:2.1,
length:12.5,
weight:5000
}
},
stegosaurus:{
维度:{
height:4,
length:9,
weight:2500
}
}
}

以下示例查找名称以字母b开头的所有恐龙。 b
$ b

  var ref = new Firebase(https://example.firebaseio.com/); 
ref.orderByKey startAt(b)。endAt(b\\\)。on(child_added,function(snapshot){
console.log(snapshot.key ));
});


I'm looking to have a searchbar where a user can search through users on Firebase and have a tableview updating as they type instead of just searching for exact matches.

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
    if searchBar.text == nil || searchBar.text == "" {
        inSearchMode = false
        tableView.reloadData()  
    } else {
        inSearchMode = true
        let lower = searchBar.text!.lowercaseString

        filteredPeopleArray = peopleArray.filter({$0.title.hasPrefix(lower) != nil})
        tableView.reloadData()
}

This code works for that, but what this would require is on load for me to fill an array with every single user currently on firebase and to constantly be appending new users as they're being created while the app is open.

I see that parse used to have a "find users where key contains string" and you would do a query to parse in your textDidChange, but I'm not seeing anything like that for Firebase. Also, would that not be taxing on data in any way to send a query to firebase every time a letter is typed in?

What method is used by like Instagram for example where you type in some letters and return back a list of users from a server with that prefix in their name? So like "Bo" might return a list of bobs and bobbys.

解决方案

I am not able to comment, but here's an article that helped me.

https://www.quora.com/How-would-you-search-a-Firebase-Realtime-Database-with-a-substring

Let say you have below firebase data

{
  "lambeosaurus": {
    "dimensions": {
      "height" : 2.1,
      "length" : 12.5,
      "weight": 5000
    }
  },
  "stegosaurus": {
    "dimensions": {
      "height" : 4,
      "length" : 9,
      "weight" : 2500
    }
  }
}

The below example finds all dinosaurs whose name starts with the letter "b".

var ref = new Firebase("https://example.firebaseio.com/");
ref.orderByKey().startAt("b").endAt("b\uf8ff").on("child_added", function(snapshot) {
  console.log(snapshot.key());
});

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

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