diff --git a/searx/results.py b/searx/results.py index 6abffb57a..a7b2e385d 100644 --- a/searx/results.py +++ b/searx/results.py @@ -135,6 +135,7 @@ class ResultContainer(object): self._number_of_results = [] self._ordered = False self.paging = False + self.unresponsive_engines = [] def extend(self, engine_name, results): for result in list(results): @@ -304,3 +305,6 @@ class ResultContainer(object): if not resultnum_sum or not self._number_of_results: return 0 return resultnum_sum / len(self._number_of_results) + + def add_unresponsive_engine(self, engine_name): + self.unresponsive_engines.append(engine_name) diff --git a/searx/search.py b/searx/search.py index 790e7d071..3ea349ade 100644 --- a/searx/search.py +++ b/searx/search.py @@ -20,6 +20,7 @@ import sys import threading from time import time from uuid import uuid4 +from flask_babel import gettext import requests.exceptions import searx.poolrequests as requests_lib from searx.engines import ( @@ -133,18 +134,21 @@ def search_one_request_safe(engine_name, query, request_params, result_container requests_exception = False if (issubclass(e.__class__, requests.exceptions.Timeout)): + result_container.add_unresponsive_engine((engine_name, gettext('timeout'))) # requests timeout (connect or read) logger.error("engine {0} : HTTP requests timeout" "(search duration : {1} s, timeout: {2} s) : {3}" .format(engine_name, search_duration, timeout_limit, e.__class__.__name__)) requests_exception = True elif (issubclass(e.__class__, requests.exceptions.RequestException)): + result_container.add_unresponsive_engine((engine_name, gettext('request exception'))) # other requests exception logger.exception("engine {0} : requests exception" "(search duration : {1} s, timeout: {2} s) : {3}" .format(engine_name, search_duration, timeout_limit, e)) requests_exception = True else: + result_container.add_unresponsive_engine((engine_name, gettext('unexpected crash'))) # others errors logger.exception('engine {0} : exception : {1}'.format(engine_name, e)) diff --git a/searx/templates/oscar/messages/no_results.html b/searx/templates/oscar/messages/no_results.html index ac3705eb8..16b5984ba 100644 --- a/searx/templates/oscar/messages/no_results.html +++ b/searx/templates/oscar/messages/no_results.html @@ -1,9 +1,17 @@ {% from 'oscar/macros.html' import icon %} +{% if unresponsive_engines %} +
{{ icon('remove-sign') }} {{ _('Error!') }} {{ _('Engines cannot retrieve results.') }}
++ {% for engine_name, error_type in unresponsive_engines %} + {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %} + {% endfor %} +
+{{ _('Please, try again later or find another searx instance.') }}
+{{ _('Number of results') }}: {{ number_of_results }}
{% endif %} + + {% if unresponsive_engines and results|length >= 1 %} +{{ _('Engines cannot retrieve results') }}:
+ {% for engine_name, error_type in unresponsive_engines %} + {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %} + {% endfor %} +