Browse Source

deactivate autocompleter by default

Thomas Pointhuber 11 years ago
parent
commit
c8cf95aa56
5 changed files with 45 additions and 21 deletions
  1. 3
    0
      searx/settings.yml
  2. 17
    15
      searx/static/js/searx.js
  3. 6
    0
      searx/templates/base.html
  4. 4
    0
      searx/templates/opensearch.xml
  5. 15
    6
      searx/webapp.py

+ 3
- 0
searx/settings.yml View File

5
     request_timeout : 2.0 # seconds
5
     request_timeout : 2.0 # seconds
6
     base_url : False
6
     base_url : False
7
 
7
 
8
+client:
9
+    autocompleter : False # only for developers, no real results yet
10
+    
8
 engines:
11
 engines:
9
   - name : wikipedia
12
   - name : wikipedia
10
     engine : wikipedia
13
     engine : wikipedia

+ 17
- 15
searx/static/js/searx.js View File

1
-window.addEvent('domready', function() {
2
-	new Autocompleter.Request.JSON('q', '/autocompleter', {
3
-		postVar:'q',
4
-		postData:{
5
-			'format': 'json'
6
-		},
7
-		ajaxOptions:{
8
-		    timeout: 5   // Correct option?
9
-		},
10
-		'minLength': 4,
11
-		'selectMode': 'type-ahead',
12
-		cache: true,
13
-		delay: 300
14
-	});
15
-});
1
+if(searx.autocompleter) {
2
+    window.addEvent('domready', function() {
3
+	    new Autocompleter.Request.JSON('q', '/autocompleter', {
4
+		    postVar:'q',
5
+		    postData:{
6
+			    'format': 'json'
7
+		    },
8
+		    ajaxOptions:{
9
+		        timeout: 5   // Correct option?
10
+		    },
11
+		    'minLength': 4,
12
+		    'selectMode': 'type-ahead',
13
+		    cache: true,
14
+		    delay: 300
15
+	    });
16
+    });
17
+}
16
 
18
 
17
 (function (w, d) {
19
 (function (w, d) {
18
     'use strict';
20
     'use strict';

+ 6
- 0
searx/templates/base.html View File

13
     {% block head %}
13
     {% block head %}
14
     <link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
14
     <link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
15
     {% endblock %}
15
     {% endblock %}
16
+    <script type="text/javascript">
17
+        searx = {};
18
+        searx.autocompleter = {% if client.autocompleter %}true{% else %}false{% endif %};
19
+    </script>
16
 </head>
20
 </head>
17
 <body>
21
 <body>
18
 <div id="container">
22
 <div id="container">
19
 {% block content %}
23
 {% block content %}
20
 {% endblock %}
24
 {% endblock %}
25
+{% if client.autocompleter %}
21
 <script src="{{ url_for('static', filename='js/mootools-core-1.4.5-min.js') }}" ></script>
26
 <script src="{{ url_for('static', filename='js/mootools-core-1.4.5-min.js') }}" ></script>
22
 <script src="{{ url_for('static', filename='js/mootools-autocompleter-1.1.2-min.js') }}" ></script>
27
 <script src="{{ url_for('static', filename='js/mootools-autocompleter-1.1.2-min.js') }}" ></script>
28
+{% endif %}
23
 <script src="{{ url_for('static', filename='js/searx.js') }}" ></script>
29
 <script src="{{ url_for('static', filename='js/searx.js') }}" ></script>
24
 </div>
30
 </div>
25
 </body>
31
 </body>

+ 4
- 0
searx/templates/opensearch.xml View File

6
   <LongName>searx metasearch</LongName>
6
   <LongName>searx metasearch</LongName>
7
   {% if method == 'get' %}
7
   {% if method == 'get' %}
8
     <Url type="text/html" method="get" template="{{ host }}?q={searchTerms}"/>
8
     <Url type="text/html" method="get" template="{{ host }}?q={searchTerms}"/>
9
+    {% if client.autocompleter %}
9
     <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
10
     <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
10
         <Param name="format" value="x-suggestions" />
11
         <Param name="format" value="x-suggestions" />
11
         <Param name="q" value="{searchTerms}" />
12
         <Param name="q" value="{searchTerms}" />
12
     </Url>
13
     </Url>
14
+    {% endif %}
13
   {% else %}
15
   {% else %}
14
     <Url type="text/html" method="post" template="{{ host }}">
16
     <Url type="text/html" method="post" template="{{ host }}">
15
         <Param name="q" value="{searchTerms}" />
17
         <Param name="q" value="{searchTerms}" />
16
     </Url>
18
     </Url>
19
+    {% if client.autocompleter %}
17
     <!-- TODO, POST REQUEST doesn't work -->
20
     <!-- TODO, POST REQUEST doesn't work -->
18
     <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
21
     <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
19
         <Param name="format" value="x-suggestions" />
22
         <Param name="format" value="x-suggestions" />
20
         <Param name="q" value="{searchTerms}" />
23
         <Param name="q" value="{searchTerms}" />
21
     </Url>
24
     </Url>
25
+    {% endif %}
22
   {% endif %}
26
   {% endif %}
23
 </OpenSearchDescription>
27
 </OpenSearchDescription>

+ 15
- 6
searx/webapp.py View File

120
     """
120
     """
121
 
121
 
122
     if not request.args and not request.form:
122
     if not request.args and not request.form:
123
-        return render('index.html')
123
+        return render(
124
+            'index.html',
125
+            client=settings['client']
126
+        )
124
 
127
 
125
     try:
128
     try:
126
         search = Search(request)
129
         search = Search(request)
127
     except:
130
     except:
128
-        return render('index.html')
131
+        return render(
132
+            'index.html',
133
+            client=settings['client']
134
+        )
129
 
135
 
130
     # TODO moar refactor - do_search integration into Search class
136
     # TODO moar refactor - do_search integration into Search class
131
     search.results, search.suggestions = do_search(search.query,
137
     search.results, search.suggestions = do_search(search.query,
206
     return render(
212
     return render(
207
         'results.html',
213
         'results.html',
208
         results=search.results,
214
         results=search.results,
215
+        client=settings['client'],
209
         q=search.request_data['q'],
216
         q=search.request_data['q'],
210
         selected_categories=search.categories,
217
         selected_categories=search.categories,
211
         paging=search.paging,
218
         paging=search.paging,
231
     else:
238
     else:
232
         request_data = request.args
239
         request_data = request.args
233
     
240
     
234
-    # TODO fix XSS-vulnerability, remove test code
241
+    # TODO fix XSS-vulnerability
235
     autocompleter.querry = request_data.get('q')
242
     autocompleter.querry = request_data.get('q')
236
     autocompleter.results = []
243
     autocompleter.results = []
237
     
244
     
238
-    if autocompleter.querry:
239
-        autocompleter.results = [autocompleter.querry + "-searx",autocompleter.querry + " asfded",autocompleter.querry + " asdf"]
245
+    if settings['client']['autocompleter']:
246
+        #TODO remove test code and add real autocompletion
247
+        if autocompleter.querry:
248
+            autocompleter.results = [autocompleter.querry + " result-1",autocompleter.querry + " result-2",autocompleter.querry + " result-3",autocompleter.querry + " result-4"]
240
     
249
     
241
     if request_data.get('format') == 'x-suggestions':
250
     if request_data.get('format') == 'x-suggestions':
242
         return Response(json.dumps([autocompleter.querry,autocompleter.results]),
251
         return Response(json.dumps([autocompleter.querry,autocompleter.results]),
344
     # chrome/chromium only supports HTTP GET....
353
     # chrome/chromium only supports HTTP GET....
345
     if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
354
     if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
346
         method = 'get'
355
         method = 'get'
347
-    ret = render('opensearch.xml', method=method, host=get_base_url())
356
+    ret = render('opensearch.xml', method=method, host=get_base_url(),client=settings['client'])
348
     resp = Response(response=ret,
357
     resp = Response(response=ret,
349
                     status=200,
358
                     status=200,
350
                     mimetype="application/xml")
359
                     mimetype="application/xml")