From 3b8765b345759a1ad8969c6eb29f7a1ff58ec4f9 Mon Sep 17 00:00:00 2001 From: Dennis <2rupnow@informatik.uni-hamburg.de> Date: Thu, 11 Apr 2019 13:36:08 +0200 Subject: [PATCH] changes to solr-backend --- ckanext/odsh/fanstatic/autocomplete.js | 2 +- ckanext/odsh/fanstatic/resource.config | 9 ++++----- ckanext/odsh/logic/action.py | 16 +++++++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ckanext/odsh/fanstatic/autocomplete.js b/ckanext/odsh/fanstatic/autocomplete.js index d03b158f..95967f5a 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 00320e6f..5fea4baa 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 98bd5526..68ddf04c 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 -- GitLab