构建动态SearchKick查询会引发语法错误

时间:2015-06-08 14:14:44

标签: ruby searchkick

如果我运行此查询:

self.send("search", where: {geo_location: { near:[ params[:latitude], params[:longitude] ]}}, boost_by: {luxury_shopper: {factor: 80}} && {movie_goer: {factor: 20}})

一切都很好,我得到了我的结果。但是,如果我运行此查询

booster = "boost_by: {luxury_shopper: {factor: 80}} && {movie_goer: {factor: 20}}"

self.send("search", where: {geo_location: { near:[ params[:latitude], params[:longitude] ]}}, booster)

我得到SyntaxError: unexpected ')', expecting =>,但我无法弄清楚为什么,或者更重要的是,如何编写此查询。助推器部分是动态的。我获得了“boost by”的任意数量的属性,并将它们插入到查询中。

1 个答案:

答案 0 :(得分:1)

你传递一个字符串,其中searchkick expects是一个哈希,我不确定它是否会自动合并选项,以下应该完成这项工作:

booster = { boost_by: { luxury_shopper: {factor: 80}, movie_goer: {factor: 20} } }
self.send("search", {where: {geo_location: { near:[ params[:latitude], params[:longitude] ]}}}.merge(booster))