forked from zaclys/searxng
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
|
||||
else:
|
||||
self.query_parts.append(search_query)
|
||||
return self
|
||||
|
||||
def getSearchQuery(self):
|
||||
if len(self.query_parts):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -44,8 +44,8 @@
|
|||
{% set first = true %}
|
||||
{% for suggestion in suggestions %}
|
||||
{% if not first %} • {% 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 %}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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="• {{ suggestion }}">
|
||||
<input type="submit" class="suggestion" value="• {{ suggestion.title }}">
|
||||
</form>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue