Skip to content

Commit

Permalink
[convert legacy params to solr] Ensured multi-word tags work.
Browse files Browse the repository at this point in the history
  • Loading branch information
icmurray committed Nov 15, 2011
1 parent 1e0b2e5 commit 081bc0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ckan/lib/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def convert_legacy_parameters_to_solr(legacy_params):
tag_list = [value_obj]
else:
raise SearchQueryError('Was expecting either a string or JSON list for the tags parameter: %r' % value)
solr_q_list.extend(['tags:%s' % tag for tag in tag_list])
solr_q_list.extend(['tags:"%s"' % tag for tag in tag_list])
else:
if ' ' in value:
value = '"%s"' % value
Expand Down
10 changes: 7 additions & 3 deletions ckan/tests/lib/test_solr_package_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ def test_1_convert_legacy_params_to_solr(self):
assert_raises(search.SearchError, convert, {'title': 'bob', 'all_fields': 'non-boolean'})
assert_equal(convert({'q': 'bob', 'order_by': 'name'}), {'q': 'bob', 'sort':'name asc'})
assert_equal(convert({'q': 'bob', 'offset': '0', 'limit': '10'}), {'q': 'bob', 'start':'0', 'rows':'10'})
assert_equal(convert({'tags': ['russian', 'tolstoy']}), {'q': 'tags:russian tags:tolstoy'})
assert_equal(convert({'tags': ['tolstoy']}), {'q': 'tags:tolstoy'})
assert_equal(convert({'tags': 'tolstoy'}), {'q': 'tags:tolstoy'})
assert_equal(convert({'tags': ['russian', 'tolstoy']}), {'q': 'tags:"russian" tags:"tolstoy"'})
assert_equal(convert({'tags': ['russian', 'multi word']}), {'q': 'tags:"russian" tags:"multi word"'})
assert_equal(convert({'tags': ['with CAPITALS']}), {'q': 'tags:"with CAPITALS"'})
assert_equal(convert({'tags': [u'with greek omega \u03a9']}), {'q': u'tags:"with greek omega \u03a9"'})
assert_equal(convert({'tags': ['tolstoy']}), {'q': 'tags:"tolstoy"'})
assert_equal(convert({'tags': 'tolstoy'}), {'q': 'tags:"tolstoy"'})
assert_equal(convert({'tags': 'more than one tolstoy'}), {'q': 'tags:"more than one tolstoy"'})
assert_raises(search.SearchError, convert, {'tags': {'tolstoy':1}})

class TestSearch(TestController):
Expand Down

0 comments on commit 081bc0c

Please sign in to comment.