SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
show engine errors in infobox && add new error alert
Noémi Ványi243d3e4298c9
diff --git a/searx/results.py b/searx/results.pyindex 6abffb57a..a7b2e385d 100644--- a/searx/results.py+++ b/searx/results.py@@ -135,6 +135,7 @@ class ResultContainer(object):self._number_of_results = []self._ordered = Falseself.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 0return 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.pyindex 790e7d071..3ea349ade 100644--- a/searx/search.py+++ b/searx/search.py@@ -20,6 +20,7 @@ import sysimport threadingfrom time import timefrom uuid import uuid4+from flask_babel import gettextimport requests.exceptionsimport searx.poolrequests as requests_libfrom searx.engines import (@@ -133,18 +134,21 @@ def search_one_request_safe(engine_name, query, request_params, result_containerrequests_exception = Falseif (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 = Trueelif (issubclass(e.__class__, requests.exceptions.RequestException)):+ result_container.add_unresponsive_engine((engine_name, gettext('request exception')))# other requests exceptionlogger.exception("engine {0} : requests exception""(search duration : {1} s, timeout: {2} s) : {3}".format(engine_name, search_duration, timeout_limit, e))requests_exception = Trueelse:+ result_container.add_unresponsive_engine((engine_name, gettext('unexpected crash')))# others errorslogger.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.htmlindex ac3705eb8..5acc205ed 100644--- a/searx/templates/oscar/messages/no_results.html+++ b/searx/templates/oscar/messages/no_results.html@@ -1,9 +1,12 @@{% from 'oscar/macros.html' import icon %}+{% if unresponsive_engines %}+<div class="alert alert-danger fade in" role="alert">+ <p><strong class="lead">{{ icon('remove-sign') }} {{ _('Error!') }}</strong> {{ _('Engines cannot retrieve results.') }}</p>+ <p><small>{{ _('Please, try again later or find another searx instance.') }}</small></p>+</div>+{% else %}<div class="alert alert-info fade in" role="alert">- <button class="close" data-dismiss="alert" type="button">- <span aria-hidden="true">×</span>- <span class="sr-only">{{ _('Close') }}</span>- </button><strong class="lead">{{ icon('info-sign') }} {{ _('Sorry!') }}</strong>{{ _('we didn\'t find any results. Please use another query or search in more categories.') }}</div>+{% endif %}diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.htmlindex 060b2a1e3..ee1052dba 100644--- a/searx/templates/oscar/results.html+++ b/searx/templates/oscar/results.html@@ -94,6 +94,16 @@{% if number_of_results != '0' %}<p><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>{% endif %}++ {% if unresponsive_engines and results|length >= 1 %}+ <div class="alert alert-danger fade in" role="alert">+ <p>{{ _('Engines cannot retrieve results') }}:</p>+ {% for engine_name, error_type in unresponsive_engines %}+ {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}+ {% endfor %}+ </div>+ {% endif %}+{% if infoboxes %}{% for infobox in infoboxes %}{% include 'oscar/infobox.html' %}diff --git a/searx/webapp.py b/searx/webapp.pyindex e2825c050..1e66590c1 100644--- a/searx/webapp.py+++ b/searx/webapp.py@@ -534,7 +534,8 @@ def index():'answers': list(result_container.answers),'corrections': list(result_container.corrections),'infoboxes': result_container.infoboxes,- 'suggestions': list(result_container.suggestions)}),+ 'suggestions': list(result_container.suggestions),+ 'unresponsive_engines': list(result_container.unresponsive_engines)}),mimetype='application/json')elif output_format == 'csv':csv = UnicodeWriter(StringIO())@@ -573,6 +574,7 @@ def index():corrections=result_container.corrections,infoboxes=result_container.infoboxes,paging=result_container.paging,+ unresponsive_engines=result_container.unresponsive_engines,current_language=search_query.lang,base_url=get_base_url(),theme=get_current_theme_name(),diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.pyindex 45a08c1ba..74fbea51c 100644--- a/tests/unit/test_webapp.py+++ b/tests/unit/test_webapp.py@@ -39,6 +39,7 @@ class ViewsTestCase(SearxTestCase):corrections=set(),suggestions=set(),infoboxes=[],+ unresponsive_engines=[],results=self.test_results,results_number=lambda: 3,results_length=lambda: len(self.test_results))