search: catch sphinx errors gracefully and show an error - merged with i18n

This commit is contained in:
Carl Chenet 2017-05-16 19:30:48 +02:00
parent 412b93babd
commit 462080150f
4 changed files with 15 additions and 9 deletions

View file

@ -19,7 +19,11 @@ class SearchController < ApplicationController
end
if @search.valid?
@search.search_for_user!(@user)
begin
@search.search_for_user!(@user)
rescue ThinkingSph::ConnectionError
flash[:error] = I18n.t 'controllers.search_controller.flasherrorsearchcontroller'
end
end
end

View file

@ -96,14 +96,9 @@ class Search
query = Riddle.escape(words)
# go go gadget search
self.results = []
self.total_results = 0
begin
self.results = ThinkingSphinx.search query, opts
self.total_results = self.results.total_entries
rescue => e
Rails.logger.info "Error from Sphinx: #{e.inspect}"
end
self.total_results = -1
self.results = ThinkingSphinx.search query, opts
self.total_results = self.results.total_entries
if self.page > self.page_count
self.page = self.page_count
@ -132,5 +127,10 @@ class Search
end
end
end
rescue ThinkingSphinx::ConnectionError => e
self.results = []
self.total_results = -1
raise e
end
end

View file

@ -439,6 +439,7 @@ en:
flashdeletedmessage: "Deleted message."
search_controller:
searchtitle: "Search"
flasherrorsearchcontroller: "Sorry, but the search engine is currently out of order"
stories_controller:
submitstorytitle: "Submit Story"
editstorytitle: "Edit Story"

View file

@ -449,6 +449,7 @@ fr:
flashdeletedmessage: "Message effacé."
search_controller:
searchtitle: "Rechercher"
flasherrorsearchcontroller: "Désolé mais le moteur de recherche est actuellement cassé"
stories_controller:
submitstorytitle: "Soumettre une info"
editstorytitle: "Éditer une info"