on master help sign in
deactivate autocompleter by default
commitc8cf95aa56590800c4f2d39a39d0a70537e7382e authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateFri 21 Mar 2014, 11:11 (13 years ago) parentcc7f3cb
5 files changed+45−21
searx/settings.yml+3 searx/static/js/searx.js+17−15 searx/templates/base.html+6 searx/templates/opensearch.xml+4 searx/webapp.py+15−6
searx/settings.yml+3
@@ -5,6 +5,9 @@ server:
55 request_timeout : 2.0 # seconds
66 base_url : False
77
8+client:
9+ autocompleter : False # only for developers, no real results yet
10+
811engines:
912 - name : wikipedia
1013 engine : wikipedia
searx/static/js/searx.js+17−15
@@ -1,18 +1,20 @@
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+}
1618
1719(function (w, d) {
1820 'use strict';
searx/templates/base.html+6
@@ -13,13 +13,19 @@
1313 {% block head %}
1414 <link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
1515 {% endblock %}
16+ <script type="text/javascript">
17+ searx = {};
18+ searx.autocompleter = {% if client.autocompleter %}true{% else %}false{% endif %};
19+ </script>
1620</head>
1721<body>
1822<div id="container">
1923{% block content %}
2024{% endblock %}
25+{% if client.autocompleter %}
2126<script src="{{ url_for('static', filename='js/mootools-core-1.4.5-min.js') }}" ></script>
2227<script src="{{ url_for('static', filename='js/mootools-autocompleter-1.1.2-min.js') }}" ></script>
28+{% endif %}
2329<script src="{{ url_for('static', filename='js/searx.js') }}" ></script>
2430</div>
2531</body>
searx/templates/opensearch.xml+4
@@ -6,18 +6,22 @@
66 <LongName>searx metasearch</LongName>
77 {% if method == 'get' %}
88 <Url type="text/html" method="get" template="{{ host }}?q={searchTerms}"/>
9+ {% if client.autocompleter %}
910 <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
1011 <Param name="format" value="x-suggestions" />
1112 <Param name="q" value="{searchTerms}" />
1213 </Url>
14+ {% endif %}
1315 {% else %}
1416 <Url type="text/html" method="post" template="{{ host }}">
1517 <Param name="q" value="{searchTerms}" />
1618 </Url>
19+ {% if client.autocompleter %}
1720 <!-- TODO, POST REQUEST doesn't work -->
1821 <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter">
1922 <Param name="format" value="x-suggestions" />
2023 <Param name="q" value="{searchTerms}" />
2124 </Url>
25+ {% endif %}
2226 {% endif %}
2327</OpenSearchDescription>
searx/webapp.py+15−6
@@ -120,12 +120,18 @@ def index():
120120 """
121121
122122 if not request.args and not request.form:
123− return render('index.html')
123+ return render(
124+ 'index.html',
125+ client=settings['client']
126+ )
124127
125128 try:
126129 search = Search(request)
127130 except:
128− return render('index.html')
131+ return render(
132+ 'index.html',
133+ client=settings['client']
134+ )
129135
130136 # TODO moar refactor - do_search integration into Search class
131137 search.results, search.suggestions = do_search(search.query,
@@ -206,6 +212,7 @@ def index():
206212 return render(
207213 'results.html',
208214 results=search.results,
215+ client=settings['client'],
209216 q=search.request_data['q'],
210217 selected_categories=search.categories,
211218 paging=search.paging,
@@ -231,12 +238,14 @@ def autocompleter():
231238 else:
232239 request_data = request.args
233240
234− # TODO fix XSS-vulnerability, remove test code
241+ # TODO fix XSS-vulnerability
235242 autocompleter.querry = request_data.get('q')
236243 autocompleter.results = []
237244
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"]
240249
241250 if request_data.get('format') == 'x-suggestions':
242251 return Response(json.dumps([autocompleter.querry,autocompleter.results]),
@@ -344,7 +353,7 @@ def opensearch():
344353 # chrome/chromium only supports HTTP GET....
345354 if request.headers.get('User-Agent', '').lower().find('webkit') >= 0:
346355 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'])
348357 resp = Response(response=ret,
349358 status=200,
350359 mimetype="application/xml")