[ckan-changes] commit/ckan: John Glover: [solr] [1277] Update package search tests for new search syntax
Bitbucket
commits-noreply at bitbucket.org
Wed Aug 31 18:09:37 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/09efb1970558/
changeset: 09efb1970558
branch: feature-1275-solr-search
user: John Glover
date: 2011-08-31 20:09:24
summary: [solr] [1277] Update package search tests for new search syntax
affected #: 1 file (125 bytes)
--- a/ckan/tests/lib/test_solr_package_search.py Wed Aug 31 18:19:35 2011 +0100
+++ b/ckan/tests/lib/test_solr_package_search.py Wed Aug 31 19:09:24 2011 +0100
@@ -37,91 +37,93 @@
return True
def test_1_all_records(self):
- result = search.query_for(model.Package).run(query=self.q_all)
+ result = search.query_for(model.Package).run({'q': self.q_all})
assert 'gils' in result['results'], result['results']
assert result['count'] == 6, result['count']
def test_1_name(self):
# exact name
- result = search.query_for(model.Package).run(query=u'gils')
+ result = search.query_for(model.Package).run({'q': u'gils'})
assert result['count'] == 1, result
assert self._pkg_names(result) == 'gils', result
def test_1_name_multiple_results(self):
- result = search.query_for(model.Package).run(query=u'gov')
+ result = search.query_for(model.Package).run({'q': u'gov'})
assert self._check_entity_names(result, ('us-gov-images', 'usa-courts-gov')), self._pkg_names(result)
assert result['count'] == 4, self._pkg_names(result)
def test_1_name_token(self):
- result = search.query_for(model.Package).run(query=u'name:gils')
+ result = search.query_for(model.Package).run({'q': u'name:gils'})
assert self._pkg_names(result) == 'gils', self._pkg_names(result)
- result = search.query_for(model.Package).run(query=u'title:gils')
+ result = search.query_for(model.Package).run({'q': u'title:gils'})
assert not self._check_entity_names(result, ('gils')), self._pkg_names(result)
def test_2_title(self):
# exact title, one word
- result = search.query_for(model.Package).run(query=u'Opengov.se')
+ result = search.query_for(model.Package).run({'q': u'Opengov.se'})
assert self._pkg_names(result) == 'se-opengov', self._pkg_names(result)
# multiple words
- result = search.query_for(model.Package).run(query=u'Government Expenditure')
+ result = search.query_for(model.Package).run({'q': u'Government Expenditure'})
assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result)
# multiple words wrong order
- result = search.query_for(model.Package).run(query=u'Expenditure Government')
+ result = search.query_for(model.Package).run({'q': u'Expenditure Government'})
assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result)
# multiple words, one doesn't match
- result = search.query_for(model.Package).run(query=u'Expenditure Government China')
+ result = search.query_for(model.Package).run({'q': u'Expenditure Government China'})
assert len(result['results']) == 0, self._pkg_names(result)
def test_3_licence(self):
# this should result, but it is here to check that at least it does not error
- result = search.query_for(model.Package).run(query=u'license:"OKD::Other (PublicsDomain)"')
+ result = search.query_for(model.Package).run({'q': u'license:"OKD::Other (PublicsDomain)"'})
assert result['count'] == 0, result
def test_quotation(self):
# multiple words quoted
- result = search.query_for(model.Package).run(query=u'"Government Expenditure"')
+ result = search.query_for(model.Package).run({'q': u'"Government Expenditure"'})
assert self._pkg_names(result) == 'uk-government-expenditure', self._pkg_names(result)
# multiple words quoted wrong order
- result = search.query_for(model.Package).run(query=u'"Expenditure Government"')
+ result = search.query_for(model.Package).run({'q': u'"Expenditure Government"'})
assert self._pkg_names(result) == '', self._pkg_names(result)
def test_string_not_found(self):
- result = search.query_for(model.Package).run(query=u'randomthing')
+ result = search.query_for(model.Package).run({'q': u'randomthing'})
assert self._pkg_names(result) == '', self._pkg_names(result)
def test_tags_field(self):
- result = search.query_for(model.Package).run(query=u'country-sweden')
+ result = search.query_for(model.Package).run({'q': u'country-sweden'})
assert self._check_entity_names(result, ['se-publications', 'se-opengov']), self._pkg_names(result)
def test_tags_token_simple(self):
- result = search.query_for(model.Package).run(query=u'tags:country-sweden')
+ result = search.query_for(model.Package).run({'q': u'tags:country-sweden'})
assert self._check_entity_names(result, ['se-publications', 'se-opengov']), self._pkg_names(result)
- result = search.query_for(model.Package).run(query=u'tags:wildlife')
+ result = search.query_for(model.Package).run({'q': u'tags:wildlife'})
assert self._pkg_names(result) == 'us-gov-images', self._pkg_names(result)
def test_tags_token_simple_with_deleted_tag(self):
# registry has been deleted
- result = search.query_for(model.Package).run(query=u'tags:registry')
+ result = search.query_for(model.Package).run({'q': u'tags:registry'})
assert self._pkg_names(result) == '', self._pkg_names(result)
def test_tags_token_multiple(self):
- result = search.query_for(model.Package).run(query=u'tags:country-sweden tags:format-pdf')
+ result = search.query_for(model.Package).run({'q': u'tags:country-sweden tags:format-pdf'})
assert self._pkg_names(result) == 'se-publications', self._pkg_names(result)
def test_tags_token_complicated(self):
- result = search.query_for(model.Package).run(query=u'tags:country-sweden tags:somethingrandom')
+ result = search.query_for(model.Package).run({'q': u'tags:country-sweden tags:somethingrandom'})
assert self._pkg_names(result) == '', self._pkg_names(result)
def test_pagination(self):
# large search
- all_results = search.query_for(model.Package).run(query=self.q_all)
+ all_results = search.query_for(model.Package).run({'q': self.q_all})
all_pkgs = all_results['results']
all_pkg_count = all_results['count']
# limit
- options = search.QueryOptions()
- options.limit = 2
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'rows': 2
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
count = result['count']
assert len(pkgs) == 2, pkgs
@@ -129,26 +131,30 @@
assert pkgs == all_pkgs[:2]
# offset
- options = search.QueryOptions()
- options.limit = 2
- options.offset = 2
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'rows': 2,
+ 'start': 2
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
assert len(pkgs) == 2, pkgs
assert pkgs == all_pkgs[2:4]
# larger offset
- options = search.QueryOptions()
- options.limit = 2
- options.offset = 4
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'rows': 2,
+ 'start': 4
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
assert len(pkgs) == 2, pkgs
assert pkgs == all_pkgs[4:6]
def test_order_by(self):
# large search
- all_results = search.query_for(model.Package).run(query=self.q_all)
+ all_results = search.query_for(model.Package).run({'q': self.q_all})
all_pkgs = all_results['results']
all_pkg_count = all_results['count']
@@ -163,36 +169,44 @@
# assert pkgs == all_pkgs, pkgs #default ordering
# name
- options = search.QueryOptions()
- options.order_by = 'name'
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'sort': 'name asc'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
sorted_fields = fields; sorted_fields.sort()
assert fields == sorted_fields, repr(fields) + repr(sorted_fields)
# title
- options = search.QueryOptions()
- options.order_by = 'title'
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'sort': 'title asc'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).title for pkg_name in pkgs]
sorted_fields = fields; sorted_fields.sort()
assert fields == sorted_fields, repr(fields) + repr(sorted_fields)
# notes
- options = search.QueryOptions()
- options.order_by = 'notes'
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'sort': 'notes asc'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).notes for pkg_name in pkgs]
sorted_fields = fields; sorted_fields.sort()
assert fields == sorted_fields, repr(fields) + repr(sorted_fields)
# extra field
- options = search.QueryOptions()
- options.order_by = 'date_released'
- result = search.query_for(model.Package).run(query=self.q_all, options=options)
+ query = {
+ 'q': self.q_all,
+ 'sort': 'date_released asc'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name) for pkg_name in pkgs]
fields = [field.extras.get('date_released') for field in fields]
@@ -200,25 +214,25 @@
assert fields == sorted_fields, repr(fields) + repr(sorted_fields)
def test_search_notes_on(self):
- result = search.query_for(model.Package).run(query=u'restrictions')
+ result = search.query_for(model.Package).run({'q': u'restrictions'})
pkgs = result['results']
count = result['count']
assert len(pkgs) == 2, pkgs
def test_search_foreign_chars(self):
- result = search.query_for(model.Package).run(query='umlaut')
+ result = search.query_for(model.Package).run({'q': 'umlaut'})
assert result['results'] == ['gils'], result['results']
- result = search.query_for(model.Package).run(query=u'thumb')
+ result = search.query_for(model.Package).run({'q': u'thumb'})
assert result['count'] == 0, result['results']
- result = search.query_for(model.Package).run(query=u'th\xfcmb')
+ result = search.query_for(model.Package).run({'q': u'th\xfcmb'})
assert result['results'] == ['gils'], result['results']
def test_groups(self):
- result = search.query_for(model.Package).run(query=u'groups:random')
+ result = search.query_for(model.Package).run({'q': u'groups:random'})
assert self._pkg_names(result) == '', self._pkg_names(result)
- result = search.query_for(model.Package).run(query=u'groups:ukgov')
+ result = search.query_for(model.Package).run({'q': u'groups:ukgov'})
assert result['count'] == 4, self._pkg_names(result)
- result = search.query_for(model.Package).run(query=u'groups:ukgov tags:us')
+ result = search.query_for(model.Package).run({'q': u'groups:ukgov tags:us'})
assert result['count'] == 2, self._pkg_names(result)
class TestSearchOverall(TestController):
@@ -233,10 +247,12 @@
search.clear()
def _check_search_results(self, terms, expected_count, expected_packages=[], only_open=False, only_downloadable=False):
- options = search.QueryOptions()
- options.filter_by_openness = only_open
- options.filter_by_downloadable = only_downloadable
- result = search.query_for(model.Package).run(query=unicode(terms))
+ query = {
+ 'q': unicode(terms),
+ 'filter_by_openness': only_open,
+ 'filter_by_downloadable': only_downloadable
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
count = result['count']
assert count == expected_count, (count, expected_count)
@@ -283,9 +299,11 @@
search.clear()
def _do_search(self, q, expected_pkgs, count=None):
- options = search.QueryOptions()
- options.order_by = 'rank'
- result = search.query_for(model.Package).run(query=q, options=options)
+ query = {
+ 'q': q,
+ 'sort': 'rank'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
if not (count is None):
@@ -294,9 +312,11 @@
assert expected_pkg in fields, expected_pkg
def _filtered_search(self, value, expected_pkgs, count=None):
- options = search.QueryOptions()
- options.order_by = 'rank'
- result = search.query_for(model.Package).run(fields={'geographic_coverage':value}, options=options)
+ query = {
+ 'q': 'geographic_coverage:%s' % value,
+ 'sort': 'rank'
+ }
+ result = search.query_for(model.Package).run(query)
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
if not (count is None):
@@ -343,7 +363,7 @@
search.clear()
def _do_search(self, department, expected_pkgs, count=None):
- result = search.query_for(model.Package).run(fields={'department': department})
+ result = search.query_for(model.Package).run({'q': 'department: %s' % department})
pkgs = result['results']
fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
if not (count is None):
@@ -353,7 +373,7 @@
def test_0_basic(self):
self._do_search(u'bcd', 'b', 1)
- self._do_search(u'cde abc', 'c', 1)
+ self._do_search(u'"cde abc"', 'c', 1)
def test_1_partial_matches(self):
# TODO: solr is not currently set up to allow partial matches
@@ -387,9 +407,11 @@
search.clear()
def _do_search(self, q, wanted_results):
- options = search.QueryOptions()
- options.order_by = 'rank'
- result = search.query_for(model.Package).run(query=q, options=options)
+ query = {
+ 'q': q,
+ 'sort': 'rank'
+ }
+ result = search.query_for(model.Package).run(query)
results = result['results']
err = 'Wanted %r, got %r' % (wanted_results, results)
assert wanted_results[0] == results[0], err
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list