on master help sign in
deactivate autocompleter by default
c8cf95aThomas Pointhuber
searx/settings.yml+3
@@ -5,6 +5,9 @@ server:
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+
8engines:
11engines:
9 - name : wikipedia
12 - name : wikipedia
10 engine : wikipedia
13 engine : wikipedia
searx/static/js/searx.js+17−15
@@ -1,18 +1,20 @@
1+if(searx.autocompleter) {
1−window.addEvent('domready', function() {
2+ window.addEvent('domready', function() {
2− new Autocompleter.Request.JSON('q', '/autocompleter', {
3+ new Autocompleter.Request.JSON('q', '/autocompleter', {
3− postVar:'q',
4+ postVar:'q',
4− postData:{
5+ postData:{
5− 'format': 'json'
6+ 'format': 'json'
6− },
7+ },
7− ajaxOptions:{
8+ ajaxOptions:{
8− timeout: 5 // Correct option?
9+ timeout: 5 // Correct option?
9− },
10+ },
10− 'minLength': 4,
11+ 'minLength': 4,
11− 'selectMode': 'type-ahead',
12+ 'selectMode': 'type-ahead',
12− cache: true,
13+ cache: true,
13− delay: 300
14+ delay: 300
14− });
15+ });
15−});
16+ });
17+}
16
18
17(function (w, d) {
19(function (w, d) {
18 'use strict';
20 'use strict';
searx/templates/base.html+6
@@ -13,13 +13,19 @@
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>
searx/templates/opensearch.xml+4
@@ -6,18 +6,22 @@
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>
searx/webapp.py+15−6
@@ -120,12 +120,18 @@ def index():
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,6 +212,7 @@ def index():
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,12 +238,14 @@ def autocompleter():
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
245+ if settings['client']['autocompleter']:
246+ #TODO remove test code and add real autocompletion
238− if autocompleter.querry:
247+ if autocompleter.querry:
239− autocompleter.results = [autocompleter.querry + "-searx",autocompleter.querry + " asfded",autocompleter.querry + " asdf"]
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,7 +353,7 @@ def opensearch():
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")