在使用 Scala 一段时间并阅读所有地方,尤其是这里
我确信我知道什么时候使用卷发。根据经验,如果我想传递要执行的代码块,我将使用花括号。
这个讨厌的错误是如何使用花括号的 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"
}
}
}
}
}
这是使用 scala 2.11.6 编译的 - 更令人困惑的是,无论我使用什么,在 intellij 调试器中评估表达式都会给出正确的结果。
我注意到只有最后一个表达式正在被评估,为什么会这样?