我有一组具有背景(例如“计算机科学”)和技能(例如“php”)的用户。我试图在强调背景或技能的同时搜索它们(用户在搜索时选择任一选项)。
我已经设法使用带有这个 JSON 字符串的 curl 来完成这个工作(在这种情况下,我强调背景):
'"query" : {
"bool" : {
"should" : [
{
"text" : {"skills" : {"query" : "php mysql html css"}}
},
{
"text" : {"backgrounds" : {"query" : "computer science", "boost" : 5}}
}
]
}
}'
现在我的问题是我不知道如何在 Tyre 中使用这个 JSON 作为查询,或者在 Tire DSL 中编写等价物。
编辑
实际上,我是通过查看轮胎源代码才知道的。
这是它的样子:
results = Users.search(:load => true) do
query do
boolean do
should { string "skills:#{skills_query}", {:boost => skills_boost}}
should {string "backgrounds:#{backgrounds_query}", {:boost => backgrounds_boost}}
end
end
end
我将要强调的一项设置为 5,另一项设置为 0。