【发布时间】:2016-05-02 19:37:30
【问题描述】:
当我将 Flashlight 与 Firebase 和 Elastic 搜索一起使用时,它确实有效:
查询
{"index":"firebase","query":"rose","type":"tasting"}
代码
...
Map<String,String> q = new HashMap<>();
q.put("index", "firebase");
q.put("type", "tasting");
q.put("query", "rose");
String key = ref.child("request").push().getKey();
ref.child("request").child(key).setValue(q);
...
但是当我想不限于只有 10 个提示时,这失败了(没有结果)
查询
{"index":"firebase","options":{"from":0,"to":50},"query":{"query_string":{"query":"rose"}},"type":"tasting"}
代码
...
HashMap<String, String> q = new HashMap<>();
q.put("query", "rose");
qs = new HashMap<>();
qs.put("query_string", q);
Map<String, Object> options = new HashMap<>();
options.put("from", 0);
options.put("to", 50);
HashMap<String, Object> qo = new HashMap<>();
qo.put("index", "firebase");
qo.put("type", "tasting");
qo.put("options", options);
qo.put("query", a);
String key = ref.child("request").push().getKey();
ref.child("request").child(key).setValue(q);
...
我使用手电筒示例中提供的选项,并为选项添加部分:
"search": {
"request": {
"$recid": {
// I can only read records assigned to me
".read": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
// I can only write new records that don't exist yet
".write": "!data.exists() && (newData.child('id').val() === auth.id || newData.child('id').val() === auth.uid)",
".validate": "newData.hasChildren(['query', 'index', 'type'])",
"index": {
// accepts arrays or strings
".validate": "(newData.isString() && newData.val().length < 1000) || newData.hasChildren()",
"$child": {
".validate": "newData.isString() && newData.val().length < 1000"
}
},
"type": {
// accepts arrays or strings
".validate": "(newData.isString() && newData.val().length < 1000) || newData.hasChildren()",
"$child": {
".validate": "newData.isString() && newData.val().length < 1000"
}
},
"query": {
// structure of the query object is pretty open-ended
".validate": "newData.isString() || newData.hasChildren()"
},
"$other": {
".validate": false
}
}
},
"response": {
"$recid": {
// I can only read/write records assigned to me
".read": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
".write": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
// Assumes that Flashlight will be writing the records using a secret or a token that has admin: true
// The only thing a logged in user needs to do is delete results after reading them
".validate": false
}
}
}
为什么可以在https://github.com/firebase/flashlight/issues/29#issuecomment-129340229找到options参数
【问题讨论】:
-
如果你使用
qo.put("options", options);而不是qo.put("from", 0); qo.put("to", 50);,它有效吗? -
@AndreiStefan 刚刚尝试过(符合安全规则)。请求的日志是:
:{"from":0,"index":"firebase","query":{"query_string":{"query":"*"}},"to":50,"type":"tasting"}but 它仍然返回不命中 -
我知道我不是在证明一个解决方案,但是我怎样才能学习如何使用 FlashLight 以及我必须学习哪种语言,换句话说,您是如何知道如何将 FlashLight 与 Firebase 一起使用的
标签: java android elasticsearch firebase