![Creative The name of the picture]()
Combine two sunspot searches with OR condition
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)
1 Answer
1
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:
first_search_conditions
second_search_conditions
Proc.new do |s|
first_search_conditions.call(s) ||
second_search_conditions.call(s)
end
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Sunspot must combine Solr queries inside.
– Alexey Spiridonov
3 hours ago