在使用Scala一段时间后,到处阅读,特别是here
我确定我知道什么时候该用卷发。作为经验法则,如果我想传递要执行的代码块,我将使用大括号。
如何使用使用花括号的elastic4s DSL出现这个令人讨厌的错误:
bool {
should {
matchQuery("title", title)
}
must {
termQuery("tags", category)
}
}汇编成:
{
"bool" : {
"must" : {
"term" : {
"tags" : "tech"
}
}
}
}在使用括号时:
bool {
should (
matchQuery("title", title)
) must (
termQuery("tags", category)
)
}给出正确的结果:
{
"bool" : {
"must" : {
"term" : {
"tags" : "tech"
}
},
"should" : {
"match" : {
"title" : {
"query" : "fake",
"type" : "boolean"
}
}
}
}
}这是使用Scala2.11.6编译的--更令人困惑的是,在intellij调试器中计算表达式会给出正确的结果,无论我使用什么。
我只注意到最后一个表达式正在被评估,为什么?
发布于 2015-04-26 14:33:17
可能不是大括号的问题,而是内插法的问题。看线
should {
matchQuery("title", title)
}
must {must进入下一行,因此它被解释为新表达式,而不是should的延续。你可能必须把它放在同一条线上的关闭支撑。
should {
matchQuery("title", title)
} must {https://stackoverflow.com/questions/29878783
复制相似问题