diff --git a/app/controllers/__init__.py b/app/controllers/__init__.py index 2c1b37c..843d708 100644 --- a/app/controllers/__init__.py +++ b/app/controllers/__init__.py @@ -23,6 +23,7 @@ from .messaging import messaging_controller from .new import new_controller from .news import news_controller +from .opensearch_suggestions import opensearch_suggestions_controller from .package import package_controller from .packages import packages_controller from .popular import popular_controller diff --git a/app/controllers/opensearch_suggestions.py b/app/controllers/opensearch_suggestions.py new file mode 100644 index 0000000..0cadd58 --- /dev/null +++ b/app/controllers/opensearch_suggestions.py @@ -0,0 +1,20 @@ +import json + +from bottle import route, response + +from ..models import package + + +@route('/opensearch_suggestions', name='opensearch_suggestions_blank') +@route('/opensearch_suggestions/', name='opensearch_suggestions') +def opensearch_suggestions_controller(terms=''): + # TODO: Optimize this call, since we're requesting a lot of stuff we don't need + results = package.find.search(terms, 'relevance', 1, 10) + + # Convert data to match suggestion extension format + # https://github.com/dewitt/opensearch/blob/master/mediawiki/Specifications/OpenSearch/Extensions/Suggestions/1.1/Draft%201.wiki + data = [terms, [package['name'] for package in results['packages']]] + + # Manually convert to JSON, since the response is a list and not a dict + response.content_type = 'application/x-suggestions+json' + return json.dumps(data) diff --git a/app/html/five_hundred.html b/app/html/five_hundred.html index ac29b6a..097a6e8 100644 --- a/app/html/five_hundred.html +++ b/app/html/five_hundred.html @@ -7,6 +7,7 @@ +