summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-10-01 17:18:18 +0200
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-10-01 17:18:18 +0200
commit510aba5e6699f76e5b9dc32db18b0f19db6e5da4 (patch)
tree9313401943a56a26de14fe6ba68b1fa588827687 /searx/webapp.py
parentbd2db71fa6921a757ff5df559535092f45010652 (diff)
downloadsearxng-510aba5e6699f76e5b9dc32db18b0f19db6e5da4.tar.gz
searxng-510aba5e6699f76e5b9dc32db18b0f19db6e5da4.zip
implement query parser and use it inside autocompletion
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 42cb42678..f66466b35 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -47,6 +47,7 @@ from searx.utils import (
from searx.https_rewrite import https_rules
from searx.languages import language_codes
from searx.search import Search
+from searx.query import Query
from searx.autocomplete import backends as autocomplete_backends
@@ -308,23 +309,46 @@ def autocompleter():
"""Return autocompleter results"""
request_data = {}
+ # select request method
if request.method == 'POST':
request_data = request.form
else:
request_data = request.args
- query = request_data.get('q', '').encode('utf-8')
+ # set blocked engines
+ if request.cookies.get('blocked_engines'):
+ blocked_engines = request.cookies['blocked_engines'].split(',') # noqa
+ else:
+ blocked_engines = []
+
+ # parse query
+ query = Query(request_data.get('q', '').encode('utf-8'), blocked_engines)
+ query.parse_query()
- if not query:
+ # check if search query is set
+ if not query.getSearchQuery():
return
+ # run autocompleter
completer = autocomplete_backends.get(request.cookies.get('autocomplete'))
+ # check if valid autocompleter is selected
if not completer:
return
- results = completer(query)
+ # run autocompletion
+ raw_results = completer(query.getSearchQuery())
+
+ # parse results (write :language and !engine back to result string)
+ results = []
+ for result in raw_results:
+ result_query = query
+ result_query.changeSearchQuery(result)
+
+ # add parsed result
+ results.append(result_query.getFullQuery())
+ # return autocompleter results
if request_data.get('format') == 'x-suggestions':
return Response(json.dumps([query, results]),
mimetype='application/json')