【问题标题】:Combine two sunspot searches with OR condition将两个太阳黑子搜索与 OR 条件相结合
【发布时间】:2018-07-24 10:04:28
【问题描述】:

如何将两个太阳黑子搜索条件与 OR 条件结合起来? 我在这里试过↓但没有成功。

first_search_conditions = Proc.new do |s|
  s.with(:store_id, 1)
end

second_search_conditions = Proc.new do |s|
  s.with(:store_id, 2)
  s.fulltext('hello') do |ft|
    ft.fields(name_words: 90)
  end
end

def search(first_block, second_block)
  Sunspot.new_search(Offer) do |s|
    s.any_of do |scope|
      first_block.call(scope)
      second_block.call(scope)
    end
  end
end

search(first_search_conditions, second_search_conditions)

【问题讨论】:

    标签: ruby-on-rails ruby sunspot sunspot-rails sunspot-solr


    【解决方案1】:

    我不知道太阳黑子,但如果你有两个 procs first_search_conditionssecond_search_conditions,并且想要分离它们,你可以构造:

    Proc.new do |s|
      first_search_conditions.call(s) ||
      second_search_conditions.call(s)
    end
    

    【讨论】:

    • Sunspot 必须在内部结合 Solr 查询。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 2014-03-29
    • 1970-01-01
    • 2014-05-30
    • 1970-01-01
    相关资源
    最近更新 更多