在没有服务器端代码的Firebase中搜索 [英] Searching in Firebase without server side code

查看:136
本文介绍了在没有服务器端代码的Firebase中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让所有的用户名字包含一个给定的字符串从Firebase。
例如,如果我有这些用户:

I am trying to get all the users having the name that contains a given string from Firebase. For example, if I have these users:

Devid, Andy, Bob

我想获得所有包含D名称的用户,所以我预计结果为:

I would like to get all the users having the name that contains a 'D' so I expect this as result:

Devid, Andy

这是我Firebase的结构:

This is my Firebase's structure at the moment:

由于Firebase是case敏感我创建了一个包含小写字母名称的属性 name _

Since Firebase is case sensitive I've created an attribute name_ that contains the lowercase name.

使用startAt和endAt名称以定义字符串开头的用户

Using startAt and endAt I can get all the users with the name starting with a defined string

ref.orderByChild("name_").startAt(text).endAt(text+"\uf8ff").on('value', ...);

但是这只给出了名称以给定字符串开头的用户,例如,如果text是'D'我会得到:

But this gives me only the users having the name that starts with a given string, for example if text is 'D' I'll get:

Devid

1)现在我的查询意味着给我所有的用户名为_的用户以一个给定的字符串开头是有办法它的意思是给我所有的用户名称包含一个给定的字符串?
EDIT:NO

1) At the moment my query means, "give me all the users having name_ that starts with a given string" is there a way to make it mean "give me all the users which name contains a given string"? NO


Firebase查询没有类似于全文搜索的内容b $ b运算符。要完成这些,你必须集成一个
外部全文搜索引擎,或者提出一个非常详细的
自定义索引方案。 Firebase和索引/搜索

2)目前我不想有服务器端代码,什么可以是一个好的和有效的方式来实现自定义索引?

2) At the moment I don't want to have server side code, what can be a good and efficient way to implement custom indexes?

感谢

推荐答案

确定 -

However this just popped into my head:

c $ c> users:
user_1234
first_name:Devid
components:
D:true
e:true
v :true
i:true
d:true
user_5678
first_name:Andy
components:
A:true
n:true
d:true
y:true
user_1010
first_name:Bob
components:
B:true
o:true
b:true

users: user_1234 first_name: "Devid" components: "D": true "e": true "v": true "i": true "d": true user_5678 first_name: "Andy" components: "A": true "n": true "d": true "y": true user_1010 first_name: "Bob" components: "B": true "o": true "b": true

和这里的一些ObjC代码,使它发生(并经过测试!)

and here's some ObjC Code to make it happen (and it's tested!)

Firebase *ref = [myRootRef childByAppendingPath:@"users"];

FQuery *q1 = [ref queryOrderedByChild:@"components/b"];
FQuery *q2 = [q1 queryEqualToValue:@1];

[q2 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {

    NSLog(@"%@", snapshot.value);

}];

此代码返回Bob。

获取所有的'd'人,将components / b更改为components / d

To get all of the 'd' people, change the "components/b" to "components/d"

编辑:

您可以变得非常疯狂,并添加更多的组合以扩大您的搜索功能。

You can get really crazy and add more combinations to expand your search capability

users:
  user_1234
    first_name: "Devid"
    components:
       "D": true
       "e": true
       "v": true
       "i": true
       "d": true
       "De": true
       "Dev": true
       "Devi": true
       "Devid": true
       "ev": true
       "evi": true
       "evid": true
       ... etc

编写几行代码以遍历名称并写出组合很简单。

It would pretty simple to code up a few lines of code to iterate over the name and write out the combinations.

很显然, (如果你有一个有限的数据集)只是读所有的名字到快照,转储到一个数组和(在ObjC)使用NSPredicate拉出你需要的。

Obviously it would be way more efficient (if you have a limited data set) to just read all of the first names into snapshot, dump them into an array and (in ObjC) use an NSPredicate to pull out what you need.

这篇关于在没有服务器端代码的Firebase中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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