diff --git a/ckanext/odsh/fanstatic/autocomplete.js b/ckanext/odsh/fanstatic/autocomplete.js index d03b158f4ed1d171767b5116bfad97c29d29732a..95967f5a337f1561312f1c58634e6d8a14dad197 100644 --- a/ckanext/odsh/fanstatic/autocomplete.js +++ b/ckanext/odsh/fanstatic/autocomplete.js @@ -16,7 +16,7 @@ $(function () { $.getJSON(url, {q: request.term}) .done(function (data) { console.log(data); - response(data.result.spellcheck.suggestions[1].suggestion); + response(data); }); } }); \ No newline at end of file diff --git a/ckanext/odsh/fanstatic/resource.config b/ckanext/odsh/fanstatic/resource.config index 00320e6fa4e7f91a82bf32121decf2fa95893a61..5fea4baab6091a70781c329469354b82fd2f3a7e 100644 --- a/ckanext/odsh/fanstatic/resource.config +++ b/ckanext/odsh/fanstatic/resource.config @@ -1,11 +1,6 @@ [depends] main = base/main -autocomplete = - vendor/jquery-ui-autocomplete/jquery-ui.css - vendor/jquery-ui-autocomplete/jquery-ui.structure.css - vendor/jquery-ui-autocomplete/jquery-ui.theme.css - vendor/jquery-ui-autocomplete/jquery-ui.js [groups] @@ -23,5 +18,9 @@ odsh_spatial_query = spatial_query.css autocomplete = + vendor/jquery-ui-autocomplete/jquery-ui.css + vendor/jquery-ui-autocomplete/jquery-ui.structure.css + vendor/jquery-ui-autocomplete/jquery-ui.theme.css + vendor/jquery-ui-autocomplete/jquery-ui.js autocomplete.js autocomplete.css diff --git a/ckanext/odsh/logic/action.py b/ckanext/odsh/logic/action.py index 98bd55263330055a0cd51ef356a73f8f189e780d..68ddf04c1cbd58305b9ceff785526fc2a3c3b0f0 100644 --- a/ckanext/odsh/logic/action.py +++ b/ckanext/odsh/logic/action.py @@ -42,16 +42,22 @@ def odsh_user_create(context, data_dict): @toolkit.side_effect_free def autocomplete(context, data_dict): query = { - 'spellcheck.q': data_dict['q'], - 'wt': 'json'} + 'terms.prefix': data_dict['q'], + 'terms.limit': 20} conn = make_connection(decode_dates=False) log.debug('Suggest query: %r' % query) try: - solr_response = conn.search('', search_handler='suggest', **query) + solr_response = conn.search('', search_handler='terms', **query) except pysolr.SolrError as e: raise SearchError('SOLR returned an error running query: %r Error: %r' % (query, e)) - suggest = solr_response.raw_response - return suggest + suggest = solr_response.raw_response.get("terms").get("suggest") + suggestions = sorted(suggest, key=suggest.get, reverse=True) + filtered_suggestions = [] + for suggestion in suggestions: + suggestion = suggestion.replace("_", "").strip() + filtered_suggestions.append(suggestion) + final_suggestions = list(sorted(set(filtered_suggestions), key=filtered_suggestions.index))[:5] + return final_suggestions