Explorar el Código

adding initial code for backend-part of autocompleter

including test-code
Thomas Pointhuber hace 11 años
padre
commit
8abf4ab993
Se han modificado 2 ficheros con 19 adiciones y 2 borrados
  1. 1
    2
      searx/static/js/searx.js
  2. 18
    0
      searx/webapp.py

+ 1
- 2
searx/static/js/searx.js Ver fichero

@@ -1,8 +1,7 @@
1 1
 window.addEvent('domready', function() {
2
-	new Autocompleter.Request.JSON('q', '/', {
2
+	new Autocompleter.Request.JSON('q', '/autocompleter', {
3 3
 		postVar:'q',
4 4
 		postData:{
5
-			'autocompleter': 1,
6 5
 			'format': 'json'
7 6
 		},
8 7
 		ajaxOptions:{

+ 18
- 0
searx/webapp.py Ver fichero

@@ -221,6 +221,24 @@ def about():
221 221
     return render('about.html')
222 222
 
223 223
 
224
+@app.route('/autocompleter', methods=['GET', 'POST'])
225
+def autocompleter():
226
+    """Return autocompleter results"""
227
+    request_data = {}
228
+    
229
+    if request.method == 'POST':
230
+        request_data = request.form
231
+    else:
232
+        request_data = request.args
233
+    
234
+    # TODO fix XSS-vulnerability, remove test code
235
+    autocompleter.querry = request_data.get('q')
236
+    autocompleter.results = [autocompleter.querry]
237
+
238
+    return Response(json.dumps(autocompleter.results),
239
+                               mimetype='application/json')
240
+
241
+
224 242
 @app.route('/preferences', methods=['GET', 'POST'])
225 243
 def preferences():
226 244
     """Render preferences page.