Skip to content

Commit

Permalink
Merge branch 'george-sattler-1905-package-search-on-resource-name-field'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 20, 2014
2 parents 10d737f + 7aea7a0 commit dc61be8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ckan/config/solr/schema.xml
Expand Up @@ -97,6 +97,7 @@

<field name="capacity" type="string" indexed="true" stored="true" multiValued="false"/>

<field name="res_name" type="textgen" indexed="true" stored="true" multiValued="true" />
<field name="res_description" type="textgen" indexed="true" stored="true" multiValued="true"/>
<field name="res_format" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="res_url" type="string" indexed="true" stored="true" multiValued="true"/>
Expand Down Expand Up @@ -161,8 +162,9 @@
<copyField source="notes" dest="text"/>
<copyField source="tags" dest="text"/>
<copyField source="groups" dest="text"/>
<copyField source="res_name" dest="text"/>
<copyField source="res_description" dest="text"/>
<copyField source="maintainer" dest="text"/>
<copyField source="author" dest="text"/>

</schema>
</schema>
7 changes: 4 additions & 3 deletions ckan/lib/search/index.py
Expand Up @@ -28,7 +28,7 @@
PACKAGE_TYPE = "package"
KEY_CHARS = string.digits + string.letters + "_-"
SOLR_FIELDS = [TYPE_FIELD, "res_url", "text", "urls", "indexed_ts", "site_id"]
RESERVED_FIELDS = SOLR_FIELDS + ["tags", "groups", "res_description",
RESERVED_FIELDS = SOLR_FIELDS + ["tags", "groups", "res_name", "res_description",
"res_format", "res_url", "res_type"]
RELATIONSHIP_TYPES = PackageRelationship.types

Expand Down Expand Up @@ -185,7 +185,8 @@ def index_package(self, pkg_dict, defer_commit=False):
pkg_dict['views_total'] = tracking_summary['total']
pkg_dict['views_recent'] = tracking_summary['recent']

resource_fields = [('description', 'res_description'),
resource_fields = [('name', 'res_name'),
('description', 'res_description'),
('format', 'res_format'),
('url', 'res_url'),
('resource_type', 'res_type')]
Expand Down Expand Up @@ -317,4 +318,4 @@ def delete_package(self, pkg_dict):
log.exception(e)
raise SearchIndexError(e)
finally:
conn.close()
conn.close()
10 changes: 10 additions & 0 deletions ckan/new_tests/logic/action/test_get.py
Expand Up @@ -580,6 +580,16 @@ def test_group_show_does_not_show_private_datasets(self):
in group['packages']], (
"group_show() should never show private datasets")

def test_package_search_on_resource_name(self):
'''
package_search() should allow searching on resource name field.
'''
resource_name = 'resource_abc'
package = factories.Resource(name=resource_name)

search_result = helpers.call_action('package_search', q='resource_abc')
eq(search_result['results'][0]['resources'][0]['name'], resource_name)


class TestBadLimitQueryParameters(object):
'''test class for #1258 non-int query parameters cause 500 errors
Expand Down

0 comments on commit dc61be8

Please sign in to comment.