How can I combine two sunspot search conditions with OR condition? I tried here ↓ but didn't have success.
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)
答案 0 :(得分:0)
I don't know about sunspot, but if you have two procs first_search_conditions
and second_search_conditions
, and want the disjunction of them, you can just construct:
Proc.new do |s|
first_search_conditions.call(s) ||
second_search_conditions.call(s)
end