Skip to content

Instantly share code, notes, and snippets.

@joxxoxo
Created May 18, 2013 14:21
Show Gist options
  • Save joxxoxo/5604566 to your computer and use it in GitHub Desktop.
Save joxxoxo/5604566 to your computer and use it in GitHub Desktop.
module Search
class Search
class << self
def perform(*args)
results = nil
with_exception_handling { results = perform_without_rescue(*args) }
::Search::SearchResults.new(results)
end
def perform_without_rescue(search_params, *classes)
Sunspot.search(classes) do
fulltext search_params.term
order_by search_params.sort_by.to_sym
paginate :page => search_params.page, :per_page => search_params.per_page
end
end
def with_exception_handling
begin
yield
rescue Exception => e
raise e unless silent_exception?
msg = "#{'='*30}\nError in search:\n#{e}\n#{e.backtrace * "\n"}#{'='*30}\n"
ExceptionNotifier::Notifier.background_exception_notification(e, name: "Sunspot #{self.name}")
Rails.logger.error(msg)
puts msg
end
end
def silent_exception?
Rails.env.test?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment