From c7220b40ead8c53b21e1533d23ffff8ae3b831bd Mon Sep 17 00:00:00 2001 From: Dalf Date: Tue, 16 Jul 2019 16:27:29 +0200 Subject: [PATCH] Suggestions: use RawTextQuery to make the suggestions URLs. Update all themes accordingly. --- searx/query.py | 1 + searx/search.py | 5 +++-- searx/templates/courgette/results.html | 4 ++-- searx/templates/legacy/results.html | 4 ++-- searx/templates/oscar/results.html | 4 ++-- searx/templates/simple/results.html | 4 ++-- searx/webapp.py | 15 ++++++++++++--- utils/standalone_searx.py | 2 +- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/searx/query.py b/searx/query.py index f76bd91d..5265ac91 100644 --- a/searx/query.py +++ b/searx/query.py @@ -145,6 +145,7 @@ class RawTextQuery(object): self.query_parts[-1] = search_query else: self.query_parts.append(search_query) + return self def getSearchQuery(self): if len(self.query_parts): diff --git a/searx/search.py b/searx/search.py index b81542f1..a51d111a 100644 --- a/searx/search.py +++ b/searx/search.py @@ -319,8 +319,9 @@ def get_search_query_from_webapp(preferences, form): for engine in categories[categ] if (engine.name, categ) not in disabled_engines) - return SearchQuery(query, query_engines, query_categories, - query_lang, query_safesearch, query_pageno, query_time_range) + return (SearchQuery(query, query_engines, query_categories, + query_lang, query_safesearch, query_pageno, query_time_range), + raw_text_query) class Search(object): diff --git a/searx/templates/courgette/results.html b/searx/templates/courgette/results.html index c72b7c3f..aa983e66 100644 --- a/searx/templates/courgette/results.html +++ b/searx/templates/courgette/results.html @@ -42,8 +42,8 @@
{{ _('Suggestions') }} {% for suggestion in suggestions %}
- - + +
{% endfor %}
diff --git a/searx/templates/legacy/results.html b/searx/templates/legacy/results.html index f0d78398..2e28bc91 100644 --- a/searx/templates/legacy/results.html +++ b/searx/templates/legacy/results.html @@ -44,8 +44,8 @@ {% set first = true %} {% for suggestion in suggestions %} {% if not first %} • {% endif %}
- - + +
{% set first = false %} {% endfor %} diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html index 3a1f8406..f712e577 100644 --- a/searx/templates/oscar/results.html +++ b/searx/templates/oscar/results.html @@ -118,8 +118,8 @@
{% for suggestion in suggestions %} {% endfor %}
diff --git a/searx/templates/simple/results.html b/searx/templates/simple/results.html index 195c478d..a8e899e5 100644 --- a/searx/templates/simple/results.html +++ b/searx/templates/simple/results.html @@ -50,11 +50,11 @@
{% for suggestion in suggestions %}
- + - +
{% endfor %}
diff --git a/searx/webapp.py b/searx/webapp.py index 4c983509..0e1fffe3 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -489,9 +489,10 @@ def index(): # search search_query = None + raw_text_query = None result_container = None try: - search_query = get_search_query_from_webapp(request.preferences, request.form) + search_query, raw_text_query = get_search_query_from_webapp(request.preferences, request.form) # search = Search(search_query) # without plugins search = SearchWithPlugins(search_query, request.user_plugins, request) result_container = search.search() @@ -580,17 +581,25 @@ def index(): ) return Response(response_rss, mimetype='text/xml') + # 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) + # return render( 'results.html', results=results, q=request.form['q'], - query_prefix=u''.join((request.form['q']).rsplit(search_query.query.decode('utf-8'), 1)), selected_categories=search_query.categories, pageno=search_query.pageno, time_range=search_query.time_range, number_of_results=format_decimal(number_of_results), advanced_search=advanced_search, - suggestions=result_container.suggestions, + suggestions=suggestion_urls, answers=result_container.answers, corrections=result_container.corrections, infoboxes=result_container.infoboxes, diff --git a/utils/standalone_searx.py b/utils/standalone_searx.py index 22316363..7bc1d32e 100755 --- a/utils/standalone_searx.py +++ b/utils/standalone_searx.py @@ -64,7 +64,7 @@ form = { preferences = searx.preferences.Preferences(['oscar'], searx.engines.categories.keys(), searx.engines.engines, []) preferences.key_value_settings['safesearch'].parse(args.safesearch) -search_query = searx.search.get_search_query_from_webapp(preferences, form) +search_query, raw_text_query = searx.search.get_search_query_from_webapp(preferences, form) search = searx.search.Search(search_query) result_container = search.search()