我在我的Firebase中有许多电报键盘,我想要一个高级字典搜索用户输入的Keyboards孩子,我的意思是在Secend中,
例如,用户输入了rock,我希望每个键盘都包含begin或中间或end,在本例中,我有3个键盘:morning、rock和rocky。
const ref = db.ref('Keyboards/rock'); //keyboard 1
const ref = db.ref('Keyboards/morning'); //keyboard 2
const ref = db.ref('Keyboards/rocky'); //keyboard 3如何获得和console.log:当用户键入rock时:rock和rocky
我的问题90%被@rymdmaskin解决了,但是高级词典搜索仍然是开放的。
equalTo,startAt和endAt不管用,我需要像contain这样的东西,有人说要用弹性搜索(https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html)
结构:

规则:
{
"rules": {
".read": true,
".write": true,
"Keyboards" : {
".indexOn": "Keyboards"
}
}
}代码:
const ref = db.ref('/');
ref.child('/').orderByChild('Keyboards').equalTo('rock').on("value", function(snapshot) {
console.log(snapshot.val());
key = snapshot.forEach(function(data) {
console.log(data.key);
});
});发布于 2017-10-21 12:44:55
谷歌目前进行全文搜索的方法似乎是与Algolia或BigQuery与Firebase的云功能同步。
用法(弹性搜索):(https://medium.com/joolsoftware/extending-firebase-with-cloud-functions-elasticsearch-129fbbb951e0)
发布于 2017-10-16 21:44:07
如果我没弄错你会做这样的事。
结构:
- Keyboards
- 0
- name: "rocks"
- children
- 0: "id"
- 1: "desc"
- 1
- name: "rocky"
- children
- 0: "id"
- 1: "desc"规则:
{
"rules": {
".read": true,
".write": true,
"Keyboards" : {
"$key": {
".indexOn": "name"
}
}
}
}代码:
const ref = db.ref('/');
ref.child('Keyboards').orderByChild('name').equalTo('rocks').on("value", function(snapshot) {
console.log(snapshot.val());
key = snapshot.forEach(function(data) {
console.log(data.key);
});
});这就是你要找的吗?
发布于 2017-10-19 20:35:03
我的建议是要么更改数据库或上的结构,要么使用这个似乎解决了问题的查询:
.orderByKey().startAt("rock")我不太确定它是否能适用于你未来的所有案例,因为我认为查询将从rock开始,但如果您有更多的键盘,则不会以rock结束。我只是基于这个来源:为Firebase数据库转换的常见SQL查询

https://stackoverflow.com/questions/46410859
复制相似问题