summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalf <alex@al-f.net>2019-07-16 16:27:29 +0200
committerDalf <alex@al-f.net>2019-07-17 09:05:29 +0200
commitc7220b40ead8c53b21e1533d23ffff8ae3b831bd (patch)
tree7131623994ea3f4bfe3e6cf7bfa0c2895918925d
parentddee4861cee8d5b08e9219d4e727acc35fc3ca32 (diff)
downloadsearxng-c7220b40ead8c53b21e1533d23ffff8ae3b831bd.tar.gz
searxng-c7220b40ead8c53b21e1533d23ffff8ae3b831bd.zip
Suggestions: use RawTextQuery to make the suggestions URLs. Update all themes accordingly.
-rw-r--r--searx/query.py1
-rw-r--r--searx/search.py5
-rw-r--r--searx/templates/courgette/results.html4
-rw-r--r--searx/templates/legacy/results.html4
-rw-r--r--searx/templates/oscar/results.html4
-rw-r--r--searx/templates/simple/results.html4
-rw-r--r--searx/webapp.py15
-rwxr-xr-xutils/standalone_searx.py2
8 files changed, 25 insertions, 14 deletions
diff --git a/searx/query.py b/searx/query.py
index f76bd91d3..5265ac914 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 b81542f1a..a51d111a2 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 c72b7c3f7..aa983e666 100644
--- a/searx/templates/courgette/results.html
+++ b/searx/templates/courgette/results.html
@@ -42,8 +42,8 @@
<div id="suggestions"><span>{{ _('Suggestions') }}</span>
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
- <input type="hidden" name="q" value="{{ suggestion }}">
- <input type="submit" value="{{ suggestion }}" />
+ <input type="hidden" name="q" value="{{ suggestion.url }}">
+ <input type="submit" value="{{ suggestion.title }}" />
</form>
{% endfor %}
</div>
diff --git a/searx/templates/legacy/results.html b/searx/templates/legacy/results.html
index f0d78398d..2e28bc91f 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 %} &bull; {% endif %}<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
- <input type="hidden" name="q" value="{{ suggestion }}">
- <input type="submit" class="suggestion" value="{{ suggestion }}" />
+ <input type="hidden" name="q" value="{{ suggestion.url }}">
+ <input type="submit" class="suggestion" value="{{ suggestion.title }}" />
</form>
{% set first = false %}
{% endfor %}
diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html
index 3a1f84067..f712e5779 100644
--- a/searx/templates/oscar/results.html
+++ b/searx/templates/oscar/results.html
@@ -118,8 +118,8 @@
<div class="panel-body">
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} suggestion_item">
- <input type="hidden" name="q" value="{{ query_prefix + suggestion }}">
- <button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
+ <input type="hidden" name="q" value="{{ suggestion.url }}">
+ <button type="submit" class="btn btn-default btn-xs">{{ suggestion.title }}</button>
</form>
{% endfor %}
</div>
diff --git a/searx/templates/simple/results.html b/searx/templates/simple/results.html
index 195c478db..a8e899e57 100644
--- a/searx/templates/simple/results.html
+++ b/searx/templates/simple/results.html
@@ -50,11 +50,11 @@
<div class="wrapper">
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
- <input type="hidden" name="q" value="{{ suggestion }}">
+ <input type="hidden" name="q" value="{{ suggestion.url }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
- <input type="submit" class="suggestion" value="&bull; {{ suggestion }}">
+ <input type="submit" class="suggestion" value="&bull; {{ suggestion.title }}">
</form>
{% endfor %}
</div>
diff --git a/searx/webapp.py b/searx/webapp.py
index 4c983509d..0e1fffe3f 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 223163639..7bc1d32ed 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()