From a6f20caf32af463b57a026ee7cb7ed6317db6b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 23 Sep 2019 17:14:32 +0200 Subject: add initial support for offline engines && command engine --- searx/webapp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index ffe9b4da9..505e93aea 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -124,6 +124,7 @@ app = Flask( app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True +app.jinja_env.add_extension('jinja2.ext.loopcontrols') app.secret_key = settings['server']['secret_key'] if not searx_debug \ @@ -538,14 +539,16 @@ def index(): if output_format == 'html': if 'content' in result and result['content']: result['content'] = highlight_content(escape(result['content'][:1024]), search_query.query) - result['title'] = highlight_content(escape(result['title'] or u''), search_query.query) + if 'title' in result and result['title']: + result['title'] = highlight_content(escape(result['title'] or u''), search_query.query) else: if result.get('content'): result['content'] = html_to_text(result['content']).strip() # removing html content and whitespace duplications result['title'] = ' '.join(html_to_text(result['title']).strip().split()) - result['pretty_url'] = prettify_url(result['url']) + if 'url' in result: + result['pretty_url'] = prettify_url(result['url']) # TODO, check if timezone is calculated right if 'publishedDate' in result: -- cgit v1.2.3 From b0f89ed4771a4238d3546323c707b1331baf5c97 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Tue, 22 Oct 2019 21:38:21 -0700 Subject: [fix] preserve bangs in corrections --- searx/webapp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 505e93aea..3bb29140a 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -610,6 +610,12 @@ def index(): 'title': suggestion }, result_container.suggestions) + + correction_urls = list(map(lambda correction: { + 'url': raw_text_query.changeSearchQuery(correction).getFullQuery(), + 'title': correction + }, + result_container.corrections)) # return render( 'results.html', @@ -622,7 +628,7 @@ def index(): advanced_search=advanced_search, suggestions=suggestion_urls, answers=result_container.answers, - corrections=result_container.corrections, + corrections=correction_urls, infoboxes=result_container.infoboxes, paging=result_container.paging, unresponsive_engines=result_container.unresponsive_engines, -- cgit v1.2.3 From 85b37233458c21b775bf98568c0a5c9260aa14fe Mon Sep 17 00:00:00 2001 From: Dalf Date: Fri, 15 Nov 2019 09:31:37 +0100 Subject: [mod] speed optimization compile XPath only once avoid redundant call to urlparse get_locale(webapp.py): avoid useless call to request.accept_languages.best_match --- searx/webapp.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 3bb29140a..00895d96c 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -154,20 +154,18 @@ outgoing_proxies = settings['outgoing'].get('proxies') or None @babel.localeselector def get_locale(): - locale = request.accept_languages.best_match(settings['locales'].keys()) - - if request.preferences.get_value('locale') != '': - locale = request.preferences.get_value('locale') + if 'locale' in request.form\ + and request.form['locale'] in settings['locales']: + return request.form['locale'] if 'locale' in request.args\ and request.args['locale'] in settings['locales']: - locale = request.args['locale'] + return request.args['locale'] - if 'locale' in request.form\ - and request.form['locale'] in settings['locales']: - locale = request.form['locale'] + if request.preferences.get_value('locale') != '': + return request.preferences.get_value('locale') - return locale + return request.accept_languages.best_match(settings['locales'].keys()) # code-highlighter -- cgit v1.2.3 From 5e5ff0cbf83fc6929545e1ca3f936a162019a2aa Mon Sep 17 00:00:00 2001 From: lorddavidiii Date: Sat, 16 Nov 2019 21:05:08 +0100 Subject: webapp.py: use html.escape if cgi.escape is not available - cgi.escape was removed in python 3.8 - also use html.escape in framalibre.py --- searx/webapp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 3bb29140a..183bf1975 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -41,7 +41,10 @@ except: logger.critical("cannot import dependency: pygments") from sys import exit exit(1) -from cgi import escape +try: + from cgi import escape +except: + from html import escape from datetime import datetime, timedelta from time import time from werkzeug.contrib.fixers import ProxyFix -- cgit v1.2.3 From 495ae59b31b6aafae484ecdfb6aece3a84f1ede7 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Sun, 25 Aug 2019 23:01:30 -0700 Subject: hide suggestions box if empty This bug happens only in python3 because map returns an iterator. --- searx/webapp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 7cf4106d3..212c874c9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -606,11 +606,11 @@ def index(): # HTML output format # suggestions: use RawTextQuery to get the suggestion URLs with the same bang - suggestion_urls = map(lambda suggestion: { - 'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(), - 'title': suggestion - }, - result_container.suggestions) + suggestion_urls = list(map(lambda suggestion: { + 'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(), + 'title': suggestion + }, + result_container.suggestions)) correction_urls = list(map(lambda correction: { 'url': raw_text_query.changeSearchQuery(correction).getFullQuery(), -- cgit v1.2.3