logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git
commit: cc7f3cb61798463036a886ae5f0ccd06aca5e625
parent 360543dec4b652950c67a7f1cc4027ee1b920a30
Author: Thomas Pointhuber <thomas.pointhuber@gmx.at>
Date:   Thu, 20 Mar 2014 15:39:17 +0100

initial implemention of autocompletion in opensearch.xml

Diffstat:

Msearx/templates/opensearch.xml11++++++++++-
Msearx/webapp.py15+++++++++++----
2 files changed, 21 insertions(+), 5 deletions(-)

diff --git 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 @@ -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'])