on master help sign in
Merge pull request #1630 from MarcAbonce/bang_fixes

[fix] Small fixes with bangs in queries

commitddee4861cee8d5b08e9219d4e727acc35fc3ca32 authorAlexandre Flament <alex@al-f.net> dateTue 16 Jul 2019, 11:08 (7 years ago) parentf750df84d38b8b
3 files changed+12−4
searx/autocomplete.py+4 searx/templates/oscar/results.html+2−2 searx/webapp.py+6−2
searx/autocomplete.py+4
@@ -16,6 +16,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1616'''
1717
1818
19+import sys
1920from lxml import etree
2021from json import loads
2122from searx import settings
@@ -26,6 +27,9 @@ from searx.engines import (
2627from searx.poolrequests import get as http_get
2728from searx.url_utils import urlencode
2829
30+if sys.version_info[0] == 3:
31+ unicode = str
32+
2933
3034def get(*args, **kwargs):
3135 if 'timeout' not in kwargs:
searx/templates/oscar/results.html+2−2
@@ -21,7 +21,7 @@
2121 <span class="result_header text-muted form-inline pull-left suggestion_item">{{ _('Try searching for:') }}</span>
2222 {% for correction in corrections %}
2323 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">
24− <input type="hidden" name="q" value="{{ correction }}">
24+ <input type="hidden" name="q" value="{{ query_prefix + correction }}">
2525 <button type="submit" class="btn btn-default btn-xs">{{ correction }}</button>
2626 </form>
2727 {% endfor %}
@@ -118,7 +118,7 @@
118118 <div class="panel-body">
119119 {% for suggestion in suggestions %}
120120 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} suggestion_item">
121− <input type="hidden" name="q" value="{{ suggestion }}">
121+ <input type="hidden" name="q" value="{{ query_prefix + suggestion }}">
122122 <button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
123123 </form>
124124 {% endfor %}
searx/webapp.py+6−2
@@ -584,6 +584,7 @@ def index():
584584 'results.html',
585585 results=results,
586586 q=request.form['q'],
587+ query_prefix=u''.join((request.form['q']).rsplit(search_query.query.decode('utf-8'), 1)),
587588 selected_categories=search_query.categories,
588589 pageno=search_query.pageno,
589590 time_range=search_query.time_range,
@@ -636,8 +637,11 @@ def autocompleter():
636637 # parse searx specific autocompleter results like !bang
637638 raw_results = searx_bang(raw_text_query)
638639
639− # normal autocompletion results only appear if max 3 inner results returned
640− if len(raw_results) <= 3 and completer:
640+ # normal autocompletion results only appear if no inner results returned
641+ # and there is a query part besides the engine and language bangs
642+ if len(raw_results) == 0 and completer and (len(raw_text_query.query_parts) > 1 or
643+ (len(raw_text_query.languages) == 0 and
644+ not raw_text_query.specific)):
641645 # get language from cookie
642646 language = request.preferences.get_value('language')
643647 if not language or language == 'all':