diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 32ac4cc968b..aa5ed714ed2 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -1831,10 +1831,9 @@ def package_search(context, data_dict): fl The parameter that controls which fields are returned in the solr - query cannot be changed. CKAN always returns the matched datasets as - dictionary objects. - if fl='id' or 'name', only this field in the dataset dictionary will - be returned. + query. + fl can be None or a list of result fields, such as ['id', 'extras_custom_field']. + if fl = None, datasets are returned as a list of full dictionary. ''' # sometimes context['schema'] is None schema = (context.get('schema') or @@ -1878,9 +1877,11 @@ def package_search(context, data_dict): data_source = 'validated_data_dict' data_dict.pop('use_default_schema', None) - # return a list of package ids - if data_dict.get('fl') not in ('id', 'name'): + result_fl = data_dict.get('fl') + if not result_fl: data_dict['fl'] = 'id {0}'.format(data_source) + else: + data_dict['fl'] = ' '.join(result_fl) # Remove before these hit solr FIXME: whitelist instead include_private = asbool(data_dict.pop('include_private', False)) @@ -1907,9 +1908,12 @@ def package_search(context, data_dict): # Add them back so extensions can use them on after_search data_dict['extras'] = extras - if data_dict.get('fl') in ['id', 'name']: + if result_fl: for package in query.results: - results.append( {data_dict.get('fl'):package} ) + if package.get('extras'): + package.update(package['extras'] ) + package.pop('extras') + results.append(package) else: for package in query.results: # get the package object