Created
February 10, 2022 11:46
-
-
Save amercader/89f87c59eb7b9f53e01ac1defe7327a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py | |
index c2646f868..205511fac 100644 | |
--- a/ckan/lib/search/query.py | |
+++ b/ckan/lib/search/query.py | |
@@ -23,7 +23,7 @@ _open_licenses = None | |
VALID_SOLR_PARAMETERS = set([ | |
'q', 'fl', 'fq', 'rows', 'sort', 'start', 'wt', 'qf', 'bf', 'boost', | |
'facet', 'facet.mincount', 'facet.limit', 'facet.field', | |
- 'extras', 'fq_list', 'tie', 'defType', 'mm', 'df' | |
+ 'extras', 'fq_list', 'tie', 'defType', 'mm', 'df', 'hl', 'hl.fl', | |
]) | |
# for (solr) package searches, this specifies the fields that are searched | |
@@ -393,6 +393,7 @@ class PackageSearchQuery(SearchQuery): | |
(query, e)) | |
self.count = solr_response.hits | |
self.results = solr_response.docs | |
+ self.highlighting = solr_response.highlighting | |
# #1683 Filter out the last row that is sometimes out of order | |
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py | |
index a8d2ff23d..56f05abdf 100644 | |
--- a/ckan/logic/action/get.py | |
+++ b/ckan/logic/action/get.py | |
@@ -1842,7 +1842,7 @@ def package_search(context, data_dict): | |
result_fl = data_dict.get('fl') | |
if not result_fl: | |
- data_dict['fl'] = 'id {0}'.format(data_source) | |
+ data_dict['fl'] = 'id index_id {0}'.format(data_source) | |
else: | |
data_dict['fl'] = ' '.join(result_fl) | |
@@ -1882,6 +1882,7 @@ def package_search(context, data_dict): | |
for package in query.results: | |
# get the package object | |
package_dict = package.get(data_source) | |
+ | |
## use data in search index if there | |
if package_dict: | |
# the package_dict still needs translating when being viewed | |
@@ -1890,6 +1891,11 @@ def package_search(context, data_dict): | |
for item in plugins.PluginImplementations( | |
plugins.IPackageController): | |
package_dict = item.before_view(package_dict) | |
+ | |
+ if query.highlighting and package.get('index_id') in query.highlighting.keys(): | |
+ for key in query.highlighting[package['index_id']]: | |
+ package_dict[key] = query.highlighting[package['index_id']][key][0] | |
+ | |
results.append(package_dict) | |
else: | |
log.error('No package_dict is coming from solr for package ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment