diff options
author | Thomas Pointhuber <thomas.pointhuber@gmx.at> | 2014-03-20 15:39:17 +0100 |
---|---|---|
committer | Thomas Pointhuber <thomas.pointhuber@gmx.at> | 2014-03-20 15:39:17 +0100 |
commit | cc7f3cb61798463036a886ae5f0ccd06aca5e625 (patch) | |
tree | e48ff073d1b50d8ffe471840f0ca8f437610fc0c /searx | |
parent | 360543dec4b652950c67a7f1cc4027ee1b920a30 (diff) | |
download | searxng-cc7f3cb61798463036a886ae5f0ccd06aca5e625.tar.gz searxng-cc7f3cb61798463036a886ae5f0ccd06aca5e625.zip |
initial implemention of autocompletion in opensearch.xml
Diffstat (limited to 'searx')
-rw-r--r-- | searx/templates/opensearch.xml | 11 | ||||
-rw-r--r-- | searx/webapp.py | 15 |
2 files changed, 21 insertions, 5 deletions
diff --git a/searx/templates/opensearch.xml b/searx/templates/opensearch.xml index 68b030b3a..b99a9bb24 100644 --- a/searx/templates/opensearch.xml +++ b/searx/templates/opensearch.xml @@ -6,9 +6,18 @@ <LongName>searx metasearch</LongName> {% if method == 'get' %} <Url type="text/html" method="get" template="{{ host }}?q={searchTerms}"/> + <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter"> + <Param name="format" value="x-suggestions" /> + <Param name="q" value="{searchTerms}" /> + </Url> {% else %} <Url type="text/html" method="post" template="{{ host }}"> - <Param name="q" value="{searchTerms}" /> + <Param name="q" value="{searchTerms}" /> + </Url> + <!-- TODO, POST REQUEST doesn't work --> + <Url type="application/x-suggestions+json" method="get" template="{{ host }}autocompleter"> + <Param name="format" value="x-suggestions" /> + <Param name="q" value="{searchTerms}" /> </Url> {% endif %} </OpenSearchDescription> diff --git a/searx/webapp.py b/searx/webapp.py index e818ae710..3034b2153 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -233,10 +233,17 @@ def autocompleter(): # 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') + autocompleter.results = [] + + if autocompleter.querry: + autocompleter.results = [autocompleter.querry + "-searx",autocompleter.querry + " asfded",autocompleter.querry + " asdf"] + + if request_data.get('format') == 'x-suggestions': + return Response(json.dumps([autocompleter.querry,autocompleter.results]), + mimetype='application/json') + else: + return Response(json.dumps(autocompleter.results), + mimetype='application/json') @app.route('/preferences', methods=['GET', 'POST']) |