mirror of
				https://github.com/searxng/searxng.git
				synced 2025-11-03 19:17:07 -05:00 
			
		
		
		
	Merge pull request #1630 from MarcAbonce/bang_fixes
[fix] Small fixes with bangs in queries
This commit is contained in:
		
						commit
						ddee4861ce
					
				@ -16,6 +16,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
 | 
				
			|||||||
'''
 | 
					'''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
from lxml import etree
 | 
					from lxml import etree
 | 
				
			||||||
from json import loads
 | 
					from json import loads
 | 
				
			||||||
from searx import settings
 | 
					from searx import settings
 | 
				
			||||||
@ -26,6 +27,9 @@ from searx.engines import (
 | 
				
			|||||||
from searx.poolrequests import get as http_get
 | 
					from searx.poolrequests import get as http_get
 | 
				
			||||||
from searx.url_utils import urlencode
 | 
					from searx.url_utils import urlencode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if sys.version_info[0] == 3:
 | 
				
			||||||
 | 
					    unicode = str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get(*args, **kwargs):
 | 
					def get(*args, **kwargs):
 | 
				
			||||||
    if 'timeout' not in kwargs:
 | 
					    if 'timeout' not in kwargs:
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,7 @@
 | 
				
			|||||||
                <span class="result_header text-muted form-inline pull-left suggestion_item">{{ _('Try searching for:') }}</span>
 | 
					                <span class="result_header text-muted form-inline pull-left suggestion_item">{{ _('Try searching for:') }}</span>
 | 
				
			||||||
                {% for correction in corrections %}
 | 
					                {% for correction in corrections %}
 | 
				
			||||||
                    <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">
 | 
					                    <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">
 | 
				
			||||||
                        <input type="hidden" name="q" value="{{ correction }}">
 | 
					                        <input type="hidden" name="q" value="{{ query_prefix + correction }}">
 | 
				
			||||||
                        <button type="submit" class="btn btn-default btn-xs">{{ correction }}</button>
 | 
					                        <button type="submit" class="btn btn-default btn-xs">{{ correction }}</button>
 | 
				
			||||||
                    </form>
 | 
					                    </form>
 | 
				
			||||||
                {% endfor %}
 | 
					                {% endfor %}
 | 
				
			||||||
@ -118,7 +118,7 @@
 | 
				
			|||||||
                <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="{{ suggestion }}">
 | 
					                        <input type="hidden" name="q" value="{{ query_prefix + suggestion }}">
 | 
				
			||||||
                        <button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
 | 
					                        <button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
 | 
				
			||||||
                    </form>
 | 
					                    </form>
 | 
				
			||||||
                    {% endfor %}
 | 
					                    {% endfor %}
 | 
				
			||||||
 | 
				
			|||||||
@ -584,6 +584,7 @@ def index():
 | 
				
			|||||||
        '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,
 | 
				
			||||||
@ -636,8 +637,11 @@ def autocompleter():
 | 
				
			|||||||
    # parse searx specific autocompleter results like !bang
 | 
					    # parse searx specific autocompleter results like !bang
 | 
				
			||||||
    raw_results = searx_bang(raw_text_query)
 | 
					    raw_results = searx_bang(raw_text_query)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # normal autocompletion results only appear if max 3 inner results returned
 | 
					    # normal autocompletion results only appear if no inner results returned
 | 
				
			||||||
    if len(raw_results) <= 3 and completer:
 | 
					    # and there is a query part besides the engine and language bangs
 | 
				
			||||||
 | 
					    if len(raw_results) == 0 and completer and (len(raw_text_query.query_parts) > 1 or
 | 
				
			||||||
 | 
					                                                (len(raw_text_query.languages) == 0 and
 | 
				
			||||||
 | 
					                                                 not raw_text_query.specific)):
 | 
				
			||||||
        # get language from cookie
 | 
					        # get language from cookie
 | 
				
			||||||
        language = request.preferences.get_value('language')
 | 
					        language = request.preferences.get_value('language')
 | 
				
			||||||
        if not language or language == 'all':
 | 
					        if not language or language == 'all':
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user