gpt4 book ai didi

javascript - Firebase 高级字典搜索

转载 作者:行者123 更新时间:2023-11-30 08:25:25 25 4
gpt4 key购买 nike

我的 Firebase 中有很多 Telegram 键盘,我想对 Keyboards 的子项进行高级词典搜索,我的意思是在第二级深度,用户进入,
例如用户输入 rock,我想让每个键盘在 beginmiddleend 包含 rock ,在这个例子中,我有 3 个键盘:morningrockrocky

const ref = db.ref('Keyboards/rock');  //keyboard 1
const ref = db.ref('Keyboards/morning'); //keyboard 2
const ref = db.ref('Keyboards/rocky'); //keyboard 3

当用户输入 rock 时,如何获取 console.log:rockrocky
我的问题 90% 已由 @rymdmaskin 解决,但高级词典搜索仍处于打开状态。
equalTostartAtendAt 不起作用,我需要像 contain 这样的东西,有人说要使用 Elastic Search ( https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html )

结构: enter image description here

规则:

{
"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);
});
});

最佳答案

如果我没猜错,你会想做这样的事情。

结构:

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

这是您要找的吗?

关于javascript - Firebase 高级字典搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46410859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com