Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

adding initial code for backend-part of autocompleter

Thomas Pointhuber8abf4ab993cd
diff --git a/searx/static/js/searx.js b/searx/static/js/searx.js
index 15e6012c2..8687a9066 100644
--- a/searx/static/js/searx.js
+++ b/searx/static/js/searx.js
@@ -1,8 +1,7 @@
window.addEvent('domready', function() {
- new Autocompleter.Request.JSON('q', '/', {
+ new Autocompleter.Request.JSON('q', '/autocompleter', {
postVar:'q',
postData:{
- 'autocompleter': 1,
'format': 'json'
},
ajaxOptions:{
diff --git a/searx/webapp.py b/searx/webapp.py
index 2f6aa4abe..e818ae710 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -221,6 +221,24 @@ def about():
return render('about.html')
[email protected]('/autocompleter', methods=['GET', 'POST'])
+def autocompleter():
+ """Return autocompleter results"""
+ request_data = {}
+
+ if request.method == 'POST':
+ request_data = request.form
+ else:
+ request_data = request.args
+
+ # TODO fix XSS-vulnerability, remove test code
+ autocompleter.querry = request_data.get('q')
+ autocompleter.results = [autocompleter.querry]
+
+ return Response(json.dumps(autocompleter.results),
+ mimetype='application/json')
+
+
@app.route('/preferences', methods=['GET', 'POST'])
def preferences():
"""Render preferences page.