太阳黑子搜索中的“很高兴”条款

时间:2014-05-13 20:10:12

标签: ruby-on-rails solr sunspot

我想在太阳黑子中搜索基本上这样说:

  • 必须包含" ruby​​"或" rails"
  • 如果它包含"合同","自由职业者"或者"兼职",这是一个额外的奖励,但这些条款都不是必要的

我知道boost,但所有示例似乎都使用with(:whatever => true),这不是我想要的。我正在做的事情看起来非常简单,我觉得很常见,所以我非常困惑。

我怎样才能做我想做的事?

1 个答案:

答案 0 :(得分:0)

这很hacky,但它应该可行

如果您的所有搜索都在同一个字段上,则可以牺牲标记化并具有:

在你的模特中:

searchable do
    string :yourfield
    integer :id # this is a trick, you'll see
    # more conditions
end

为了您的搜索:

search = Yourmodel.search
    with(:yourfield).any_of(['ruby'],['rails'])
    any_of do
        with(:yourfield).any_of(['contract'],['freelance'],['part-time'])
        with(:id).greater_than_or_equal_to(1) #all fields!!
    end
end
相关问题