diff --git a/gui/src/components/Repo.js b/gui/src/components/Repo.js index c36252ce1c887b44943d1ffa38bfd7a74bdc2a9f..fa612b7bca5667adbc5c3764d5db8bfbb6e87d67 100644 --- a/gui/src/components/Repo.js +++ b/gui/src/components/Repo.js @@ -61,7 +61,7 @@ class Repo extends React.Component { state = { data: [], page: 1, - rowsPerPage: 5, + rowsPerPage: 10, total: 0, loading: true, owner: 'all' diff --git a/gui/src/components/api.js b/gui/src/components/api.js index 47445af4d9b9e1fc06b54f0dec6ab72760bcb518..750e5688f72dbb5a80ea5c0caced7d273a4b201c 100644 --- a/gui/src/components/api.js +++ b/gui/src/components/api.js @@ -199,10 +199,10 @@ class Api { async repoAll(page, perPage, owner) { const client = await this.swaggerPromise - return client.apis.repo.get_calcs({ + return client.apis.repo.search({ page: page, per_page: perPage, - ower: owner || 'all' + owner: owner || 'all' }) .catch(this.handleApiError) .then(response => response.body) diff --git a/nomad/api/repo.py b/nomad/api/repo.py index 7a28500d43aea3711fb647f8961b76c686cd7411..dd035684f6029756199251c6c855027af01ae12c 100644 --- a/nomad/api/repo.py +++ b/nomad/api/repo.py @@ -81,7 +81,7 @@ for search_quantity in search.search_quantities.keys(): @ns.route('/') class RepoCalcsResource(Resource): - @api.doc('get_calcs') + @api.doc('search') @api.response(400, 'Invalid requests, e.g. wrong owner type or bad quantities') @api.expect(repo_request_parser, validate=True) @api.marshal_with(repo_calcs_model, skip_none=True, code=200, description='Metadata send') @@ -97,12 +97,12 @@ class RepoCalcsResource(Resource): that have the certain value. You can also use these aggregations on an empty search to determine the possible values. """ - page = int(request.args.get('page', 0)) + page = int(request.args.get('page', 1)) per_page = int(request.args.get('per_page', 10)) owner = request.args.get('owner', 'all') try: - assert page >= 0 + assert page >= 1 assert per_page > 0 except AssertionError: abort(400, message='invalid pagination') diff --git a/nomad/client/misc.py b/nomad/client/misc.py index beb9b9e8334aee95e5fd58016e3620781a15f42a..0d071b0d61611ac1ed60ef8119412ca527428c55 100644 --- a/nomad/client/misc.py +++ b/nomad/client/misc.py @@ -59,7 +59,7 @@ def run_worker(): processing.app.worker_main(['worker', '--loglevel=INFO']) -@run.command(help='Run both api and worker with watchdog.') +@run.command(help='Run both api and worker.') def apiworker(): executor = ProcessPoolExecutor(2) loop = asyncio.get_event_loop() diff --git a/nomad/infrastructure.py b/nomad/infrastructure.py index d26693ea9a0d909edb2a670c51587402229ea7e5..099fbd8ab53b1ebe4b0d5a935de5f6b066877721 100644 --- a/nomad/infrastructure.py +++ b/nomad/infrastructure.py @@ -220,10 +220,10 @@ def reset(): try: if not elastic_client: setup_elastic() - elastic_client.indices.delete(index=config.elastic.index_name) - from nomad.search import Entry - Entry.init(index=config.elastic.index_name) - logger.info('elastic index resetted') + elastic_client.indices.delete(index=config.elastic.index_name) + from nomad.search import Entry + Entry.init(index=config.elastic.index_name) + logger.info('elastic index resetted') except Exception as e: logger.error('exception resetting elastic', exc_info=e) diff --git a/nomad/search.py b/nomad/search.py index c3b4975293813c12b03f8112af165aaf05166488..ae019015acb23919ea5c183f26a5190fde4f5632 100644 --- a/nomad/search.py +++ b/nomad/search.py @@ -221,13 +221,13 @@ elastic field and description. def aggregate_search( - page: int = 0, per_page: int = 10, q: Q = None, **kwargs) -> Tuple[int, List[dict], Dict[str, Dict[str, int]]]: + page: int = 1, per_page: int = 10, q: Q = None, **kwargs) -> Tuple[int, List[dict], Dict[str, Dict[str, int]]]: """ Performs a search and returns paginated search results and aggregation bucket sizes based on key quantities. Arguments: - page: The page to return starting with 0 + page: The page to return starting with page 1 per_page: Results per page q: An *elasticsearch_dsl* query used to further filter the results (via `and`) aggregations: A customized list of aggregations to perform. Keys are index fields, @@ -238,7 +238,7 @@ def aggregate_search( the aggregation data. """ - search = Search() + search = Search(index=config.elastic.index_name) if q is not None: search = search.query(q) @@ -259,7 +259,7 @@ def aggregate_search( else: search.aggs.bucket(aggregation, A('terms', field=aggregation, size=size)) - response = search[page * per_page: (page + 1) * per_page].execute() # pylint: disable=no-member + response = search[(page - 1) * per_page: page * per_page].execute() # pylint: disable=no-member total_results = response.hits.total search_results = [hit.to_dict() for hit in response.hits] diff --git a/requirements.txt b/requirements.txt index 6f823e1a74eda69744ea4cf0f076ca094b5bc45f..54adfe8cd9baf9bf65413afd41a3a699b605c846 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,7 +42,6 @@ bravado PyJWT jsonschema[format] python-magic -watchgod # dev/ops related setuptools diff --git a/tests/test_api.py b/tests/test_api.py index 885b18b52c62bf66582f667f34c6cb8db0bd470e..dbe0ff0d6f5f013b6dc0a1b5e509f44b9887d054 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -620,14 +620,16 @@ class TestRepo(UploadFilesBasedTests): assert len(aggregations['system']) == 1 assert value in aggregations['system'] - def test_search_pagination(self, client, example_elastic_calcs, no_warn): - rv = client.get('/repo/?page=1&per_page=1') + @pytest.mark.parametrize('n_results, page, per_page', [(2, 1, 5), (1, 1, 1), (0, 2, 3)]) + def test_search_pagination(self, client, example_elastic_calcs, no_warn, n_results, page, per_page): + rv = client.get('/repo/?page=%d&per_page=%d' % (page, per_page)) assert rv.status_code == 200 data = json.loads(rv.data) results = data.get('results', None) + assert data['pagination']['total'] == 2 assert results is not None assert isinstance(results, list) - assert len(results) == 1 + assert len(results) == n_results def test_search_user_authrequired(self, client, example_elastic_calcs, no_warn): rv = client.get('/repo/?owner=user')