From 94196c4b6c92da621b45db6332f594d59af52471 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 14 Nov 2016 15:49:06 +0100 Subject: [enh] show traceback of search errors --- searx/webapp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index d3d5bb51e..7d5adaf07 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -410,7 +410,8 @@ def index(): # search = Search(search_query) # without plugins search = SearchWithPlugins(search_query, request) result_container = search.search() - except: + except Exception: + logger.exception('search error') return render( 'index.html', ) -- cgit v1.2.3 From 832cf37a97b97061a26e2fdf49c293d26e917ef5 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 14 Nov 2016 22:07:23 +0100 Subject: [enh] display errors also tried flask's flash feature but flask creates session cookies if it isn't flushed. Avoiding session cookies to preserve privacy --- searx/webapp.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 7d5adaf07..68902a6cd 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -344,6 +344,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['cookies'] = request.cookies + kwargs['errors'] = request.errors + kwargs['instance_name'] = settings['general']['instance_name'] kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab') @@ -364,15 +366,16 @@ def render(template_name, override_theme=None, **kwargs): @app.before_request def pre_request(): - # merge GET, POST vars + request.errors = [] + preferences = Preferences(themes, categories.keys(), engines, plugins) try: preferences.parse_cookies(request.cookies) except: - # TODO throw error message to the user - logger.warning('Invalid config') + request.errors.append(gettext('Invalid settings, please edit your preferences')) request.preferences = preferences + # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): @@ -397,7 +400,7 @@ def index(): Supported outputs: html, json, csv, rss. """ - if not request.args and not request.form: + if request.form.get('q') is None: return render( 'index.html', ) @@ -410,7 +413,8 @@ def index(): # search = Search(search_query) # without plugins search = SearchWithPlugins(search_query, request) result_container = search.search() - except Exception: + except: + request.errors.append(gettext('search error')) logger.exception('search error') return render( 'index.html', @@ -573,7 +577,7 @@ def preferences(): try: request.preferences.parse_form(request.form) except ValidationException: - # TODO use flash feature of flask + request.errors.append(gettext('Invalid settings, please edit your preferences')) return resp return request.preferences.save(resp) -- cgit v1.2.3 From a757c2f005f38a97d7ebe53ab7271e26c13b7197 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 14 Nov 2016 22:15:03 +0100 Subject: [fix] remove unused imports --- searx/webapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 68902a6cd..45332ba99 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -62,8 +62,8 @@ from searx.utils import ( ) from searx.version import VERSION_STRING from searx.languages import language_codes -from searx.search import Search, SearchWithPlugins, get_search_query_from_webapp -from searx.query import RawTextQuery, SearchQuery +from searx.search import SearchWithPlugins, get_search_query_from_webapp +from searx.query import RawTextQuery from searx.autocomplete import searx_bang, backends as autocomplete_backends from searx.plugins import plugins from searx.preferences import Preferences, ValidationException -- cgit v1.2.3 From 827f9e41ca84638d873997001b53e7f4a62a78aa Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 15 Nov 2016 09:56:18 +0100 Subject: [fix] gettext requires request.preferences --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 45332ba99..090df57e2 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -369,11 +369,11 @@ def pre_request(): request.errors = [] preferences = Preferences(themes, categories.keys(), engines, plugins) + request.preferences = preferences try: preferences.parse_cookies(request.cookies) except: request.errors.append(gettext('Invalid settings, please edit your preferences')) - request.preferences = preferences # merge GET, POST vars # request.form -- cgit v1.2.3 From 971ed0abd159625bd01d0b3ca52c90b394711d77 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 19 Nov 2016 20:53:51 +0100 Subject: [enh] add quick answer functionality with an example answerer --- searx/webapp.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 090df57e2..8996aa2b9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -67,6 +67,7 @@ from searx.query import RawTextQuery from searx.autocomplete import searx_bang, backends as autocomplete_backends from searx.plugins import plugins from searx.preferences import Preferences, ValidationException +from searx.answerers import answerers # check if the pyopenssl, ndg-httpsclient, pyasn1 packages are installed. # They are needed for SSL connection without trouble, see #298 @@ -612,6 +613,7 @@ def preferences(): language_codes=language_codes, engines_by_category=categories, stats=stats, + answerers=[{'info': a.self_info(), 'keywords': a.keywords} for a in answerers], disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, -- cgit v1.2.3 From ef2ef7974ab9bf55c5193a30544f71d8ca04f7b0 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 9 Dec 2016 19:10:33 +0100 Subject: [enh] central html escaping of results --- searx/webapp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 8996aa2b9..352a49fb6 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -40,7 +40,7 @@ except: logger.critical("cannot import dependency: pygments") from sys import exit exit(1) - +from cgi import escape from datetime import datetime, timedelta from urllib import urlencode from urlparse import urlparse, urljoin @@ -433,8 +433,9 @@ def index(): for result in results: if output_format == 'html': if 'content' in result and result['content']: - result['content'] = highlight_content(result['content'][:1024], search_query.query.encode('utf-8')) - result['title'] = highlight_content(result['title'], search_query.query.encode('utf-8')) + result['content'] = highlight_content(escape(result['content'][:1024]), + search_query.query.encode('utf-8')) + result['title'] = highlight_content(escape(result['title']), search_query.query.encode('utf-8')) else: if result.get('content'): result['content'] = html_to_text(result['content']).strip() -- cgit v1.2.3 From d80fb2c8e8995facb3a25c152c47a93eecf1fee4 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 9 Dec 2016 19:57:28 +0100 Subject: [enh] central handling of empty result titles --- searx/webapp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 352a49fb6..cdac52a45 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -435,7 +435,8 @@ def index(): if 'content' in result and result['content']: result['content'] = highlight_content(escape(result['content'][:1024]), search_query.query.encode('utf-8')) - result['title'] = highlight_content(escape(result['title']), search_query.query.encode('utf-8')) + result['title'] = highlight_content(escape(result['title'] or u''), + search_query.query.encode('utf-8')) else: if result.get('content'): result['content'] = html_to_text(result['content']).strip() -- cgit v1.2.3