diff --git a/ckanext/odsh/controller.py b/ckanext/odsh/controller.py index 83831680c05af6866581652dcf8e38685e391ef6..906afa0c6537fd6f5cc9bd6740631c5c9d2928d1 100644 --- a/ckanext/odsh/controller.py +++ b/ckanext/odsh/controller.py @@ -167,8 +167,9 @@ class OdshFeedController(FeedController): class OdshAutocompleteController(ApiController): def autocomplete(self): + from ckan.common import request query = { - 'spellcheck.q': 'Obs', + 'spellcheck.q': request.get('q', ''), 'wt': 'json'} conn = make_connection(decode_dates=False) @@ -180,7 +181,4 @@ class OdshAutocompleteController(ApiController): (query, e)) suggest = solr_response.raw_response.get('spellcheck') - hits = suggest.get('suggestions')[0].get(query.get('spellcheck.q')).get('numFound') - if hits >= 1: - return base.response.body_file.write(suggest.get('suggestions')[0].get(query.get('spellcheck.q')) - .get('suggestion')[0]) + return suggest diff --git a/ckanext/odsh/fanstatic/autocomplete.css b/ckanext/odsh/fanstatic/autocomplete.css new file mode 100644 index 0000000000000000000000000000000000000000..3ae7be7ccffad1a21d200cc9648a6a07cb42bc4d --- /dev/null +++ b/ckanext/odsh/fanstatic/autocomplete.css @@ -0,0 +1,8 @@ +.ui-autocomplete .ui-menu-item a, +.ui-autocomplete .ui-menu-item a:active, +.ui-autocomplete .ui-menu-item a:focus, +.ui-autocomplete .ui-menu-item a:hover, +.ui-autocomplete .ui-menu-item a:visited { + display: block; + text-decoration: none; +} diff --git a/ckanext/odsh/fanstatic/autocomplete.js b/ckanext/odsh/fanstatic/autocomplete.js new file mode 100644 index 0000000000000000000000000000000000000000..3cd334c3c427cd4d9bbdab4100cf9f9cedc00e66 --- /dev/null +++ b/ckanext/odsh/fanstatic/autocomplete.js @@ -0,0 +1,21 @@ +'use strict'; + +$(function () { + + // Activate search suggestions for the search bar in the header and for the + // search bar used in the body. + $('.site-search input, .search').autocomplete({ + delay: 500, + html: true, + minLength: 2, + source: function (request, response) { + var url = ckan.SITE_ROOT + '/autocomplete'; + $.getJSON(url, {q: request.term}) + .done(function (data) { + console.log(data); + response(data['result']); + }); + } + }); + +}) diff --git a/ckanext/odsh/templates/base.html b/ckanext/odsh/templates/base.html index 5962c139dbd823b28c0289e0794ea1e724b245c9..a060e606c21670d86f8f1ac6192b0009b939a4bb 100644 --- a/ckanext/odsh/templates/base.html +++ b/ckanext/odsh/templates/base.html @@ -6,6 +6,8 @@ <link rel="stylesheet" href="/odsh.css?refresh={{ range(1,10000) | random }}" /> <link rel="stylesheet" href="/odsh_header.css?refresh={{ range(1,10000) | random }}" /> <link rel="stylesheet" href="/bootstrap-multiselect.css" /> +<link rel="stylesheet" href="/autocomplete.css" /> +{% resource 'odsh/autocomplete.js' %} {% endblock %} {% block head_extras %}