mirror of
https://github.com/searxng/searxng
synced 2024-11-16 21:25:37 +00:00
Suggestions: use RawTextQuery to make the suggestions URLs. Update all themes accordingly.
This commit is contained in:
parent
ddee4861ce
commit
c7220b40ea
@ -145,6 +145,7 @@ class RawTextQuery(object):
|
|||||||
self.query_parts[-1] = search_query
|
self.query_parts[-1] = search_query
|
||||||
else:
|
else:
|
||||||
self.query_parts.append(search_query)
|
self.query_parts.append(search_query)
|
||||||
|
return self
|
||||||
|
|
||||||
def getSearchQuery(self):
|
def getSearchQuery(self):
|
||||||
if len(self.query_parts):
|
if len(self.query_parts):
|
||||||
|
@ -319,8 +319,9 @@ def get_search_query_from_webapp(preferences, form):
|
|||||||
for engine in categories[categ]
|
for engine in categories[categ]
|
||||||
if (engine.name, categ) not in disabled_engines)
|
if (engine.name, categ) not in disabled_engines)
|
||||||
|
|
||||||
return SearchQuery(query, query_engines, query_categories,
|
return (SearchQuery(query, query_engines, query_categories,
|
||||||
query_lang, query_safesearch, query_pageno, query_time_range)
|
query_lang, query_safesearch, query_pageno, query_time_range),
|
||||||
|
raw_text_query)
|
||||||
|
|
||||||
|
|
||||||
class Search(object):
|
class Search(object):
|
||||||
|
@ -42,8 +42,8 @@
|
|||||||
<div id="suggestions"><span>{{ _('Suggestions') }}</span>
|
<div id="suggestions"><span>{{ _('Suggestions') }}</span>
|
||||||
{% for suggestion in suggestions %}
|
{% for suggestion in suggestions %}
|
||||||
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
|
<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="submit" value="{{ suggestion }}" />
|
<input type="submit" value="{{ suggestion.title }}" />
|
||||||
</form>
|
</form>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,8 +44,8 @@
|
|||||||
{% set first = true %}
|
{% set first = true %}
|
||||||
{% for suggestion in suggestions %}
|
{% for suggestion in suggestions %}
|
||||||
{% if not first %} • {% endif %}<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
|
{% if not first %} • {% endif %}<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="submit" class="suggestion" value="{{ suggestion }}" />
|
<input type="submit" class="suggestion" value="{{ suggestion.title }}" />
|
||||||
</form>
|
</form>
|
||||||
{% set first = false %}
|
{% set first = false %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -118,8 +118,8 @@
|
|||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% for suggestion in suggestions %}
|
{% 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">
|
<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 }}">
|
<input type="hidden" name="q" value="{{ suggestion.url }}">
|
||||||
<button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
|
<button type="submit" class="btn btn-default btn-xs">{{ suggestion.title }}</button>
|
||||||
</form>
|
</form>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,11 +50,11 @@
|
|||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
{% for suggestion in suggestions %}
|
{% for suggestion in suggestions %}
|
||||||
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
|
<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="language" value="{{ current_language }}">
|
||||||
<input type="hidden" name="safesearch" value="{{ safesearch }}">
|
<input type="hidden" name="safesearch" value="{{ safesearch }}">
|
||||||
<input type="hidden" name="theme" value="{{ theme }}">
|
<input type="hidden" name="theme" value="{{ theme }}">
|
||||||
<input type="submit" class="suggestion" value="• {{ suggestion }}">
|
<input type="submit" class="suggestion" value="• {{ suggestion.title }}">
|
||||||
</form>
|
</form>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -489,9 +489,10 @@ def index():
|
|||||||
|
|
||||||
# search
|
# search
|
||||||
search_query = None
|
search_query = None
|
||||||
|
raw_text_query = None
|
||||||
result_container = None
|
result_container = None
|
||||||
try:
|
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 = Search(search_query) # without plugins
|
||||||
search = SearchWithPlugins(search_query, request.user_plugins, request)
|
search = SearchWithPlugins(search_query, request.user_plugins, request)
|
||||||
result_container = search.search()
|
result_container = search.search()
|
||||||
@ -580,17 +581,25 @@ def index():
|
|||||||
)
|
)
|
||||||
return Response(response_rss, mimetype='text/xml')
|
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(
|
return render(
|
||||||
'results.html',
|
'results.html',
|
||||||
results=results,
|
results=results,
|
||||||
q=request.form['q'],
|
q=request.form['q'],
|
||||||
query_prefix=u''.join((request.form['q']).rsplit(search_query.query.decode('utf-8'), 1)),
|
|
||||||
selected_categories=search_query.categories,
|
selected_categories=search_query.categories,
|
||||||
pageno=search_query.pageno,
|
pageno=search_query.pageno,
|
||||||
time_range=search_query.time_range,
|
time_range=search_query.time_range,
|
||||||
number_of_results=format_decimal(number_of_results),
|
number_of_results=format_decimal(number_of_results),
|
||||||
advanced_search=advanced_search,
|
advanced_search=advanced_search,
|
||||||
suggestions=result_container.suggestions,
|
suggestions=suggestion_urls,
|
||||||
answers=result_container.answers,
|
answers=result_container.answers,
|
||||||
corrections=result_container.corrections,
|
corrections=result_container.corrections,
|
||||||
infoboxes=result_container.infoboxes,
|
infoboxes=result_container.infoboxes,
|
||||||
|
@ -64,7 +64,7 @@ form = {
|
|||||||
preferences = searx.preferences.Preferences(['oscar'], searx.engines.categories.keys(), searx.engines.engines, [])
|
preferences = searx.preferences.Preferences(['oscar'], searx.engines.categories.keys(), searx.engines.engines, [])
|
||||||
preferences.key_value_settings['safesearch'].parse(args.safesearch)
|
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)
|
search = searx.search.Search(search_query)
|
||||||
result_container = search.search()
|
result_container = search.search()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user