diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py index 73a31107544..0cd266304ad 100644 --- a/ckan/lib/search/query.py +++ b/ckan/lib/search/query.py @@ -247,7 +247,14 @@ def run(self, query): query['q'] = "*:*" # number of results - query['rows'] = min(1000, int(query.get('rows', 10))) + rows_to_return = min(1000, int(query.get('rows', 10))) + if rows_to_return > 0: + # #1683 Work around problem of last result being out of order + # in SOLR 1.4 + rows_to_query = rows_to_return + 1 + else: + rows_to_query = rows_to_return + query['rows'] = rows_to_query # order by score if no 'sort' term given order_by = query.get('sort') @@ -297,6 +304,9 @@ def run(self, query): self.count = response.get('numFound', 0) self.results = response.get('docs', []) + # #1683 Filter out the last row that is sometimes out of order + self.results = self.results[:rows_to_return] + # get any extras and add to 'extras' dict for result in self.results: extra_keys = filter(lambda x: x.startswith('extras_'), result.keys()) diff --git a/ckan/tests/lib/test_cli.py b/ckan/tests/lib/test_cli.py index f6e383f0c78..4adda216572 100644 --- a/ckan/tests/lib/test_cli.py +++ b/ckan/tests/lib/test_cli.py @@ -19,6 +19,10 @@ def setup_class(cls): model.Package.by_name(u'warandpeace').delete() model.repo.commit_and_remove() + @classmethod + def teardown_class(cls): + model.repo.rebuild_db() + def test_simple_dump_csv(self): csv_filepath = '/tmp/dump.tmp' self.db.args = ('simple-dump-csv %s' % csv_filepath).split() diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py index 9ce457d42bd..e099a57f93d 100644 --- a/ckan/tests/lib/test_dictization.py +++ b/ckan/tests/lib/test_dictization.py @@ -105,11 +105,6 @@ def teardown_class(cls): model.repo.rebuild_db() model.Session.remove() - def teardonwn(self): - model.Session.remove() - - - def remove_changable_columns(self, dict): for key, value in dict.items(): if key.endswith('id') and key <> 'license_id':