Skip to content

Commit

Permalink
Package search rows limit is now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Sep 28, 2018
1 parent 523c6e6 commit 034b90a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ckan/lib/search/query.py
Expand Up @@ -312,7 +312,9 @@ def run(self, query, permission_labels=None, **kwargs):
query['q'] = "*:*"

# number of results
rows_to_return = min(1000, int(query.get('rows', 10)))
rows_to_return = min(
int(config.get('ckan.search.rows_max', 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
Expand Down
4 changes: 2 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -1694,8 +1694,8 @@ def package_search(context, data_dict):
documentation, this is a comma-separated string of field names and
sort-orderings.
:type sort: string
:param rows: the number of matching rows to return. There is a hard limit
of 1000 datasets per query.
:param rows: the number of matching rows (datasets) to return. Default is
10. Upper limit is 1000, depending on site configuration.
:type rows: int
:param start: the offset in the complete result for where the set of
returned datasets should begin.
Expand Down
19 changes: 19 additions & 0 deletions ckan/tests/logic/action/test_get.py
Expand Up @@ -892,6 +892,25 @@ def test_bad_solr_parameter(self):
# SOLR error is 'Missing sort order' or 'Missing_sort_order',
# depending on the solr version.

def _create_bulk_datasets(self, name, count):
from ckan import model
model.repo.new_revision()
pkgs = [model.Package(name='{}_{}'.format(name, i))
for i in range(count)]
model.Session.add_all(pkgs)
model.repo.commit_and_remove()

def test_rows_returned_default(self):
self._create_bulk_datasets('rows_default', 11)
results = logic.get_action('package_search')({}, {})
eq(len(results['results']), 10) # i.e. 'rows' default value

@helpers.change_config('ckan.search.rows_max', '12')
def test_rows_returned_limited(self):
self._create_bulk_datasets('rows_limited', 14)
results = logic.get_action('package_search')({}, {'rows': '15'})
eq(len(results['results']), 12) # i.e. ckan.search.rows_max

def test_facets(self):
org = factories.Organization(name='test-org-facet', title='Test Org')
factories.Dataset(owner_org=org['id'])
Expand Down
12 changes: 12 additions & 0 deletions doc/maintaining/configuration.rst
Expand Up @@ -734,6 +734,18 @@ Default value: ``None``

List of the extra resource fields that would be used when searching.

.. _ckan.search.rows_max:

ckan.search.rows_max
^^^^^^^^^^^^^^^^^^^^

Example::

ckan.search.rows_max = 1000

Default value: ``1000``

Maximum allowed value for ``package_search``'s ``rows`` parameter.

Redis Settings
---------------
Expand Down

0 comments on commit 034b90a

Please sign in to comment.