From 7f2ce3813e8c72434e6b8547411d1866d622e7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20De=CC=81le=CC=80ze?= Date: Wed, 23 Sep 2020 08:25:53 +0200 Subject: [PATCH] records: sort by most recent descending by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For all record types, the default behavior is to have the most recent records first, if no query is specified. * Configures sort options and default sort for all record types. * Adds `_created` and `_updated` fields to deposit's elasticsearch mapping. * Closes #318. Co-Authored-by: Sébastien Délèze --- sonar/config.py | 42 +++++++++++-------- .../mappings/v6/deposits/deposit-v1.0.0.json | 6 +++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/sonar/config.py b/sonar/config.py index 59e1c08e..6231f105 100644 --- a/sonar/config.py +++ b/sonar/config.py @@ -524,26 +524,32 @@ def _(x): } """REST search facets.""" -RECORDS_REST_SORT_OPTIONS = dict(documents=dict( - bestmatch=dict( - title=_('Best match'), - fields=['-_score'], - default_order='asc', - order=2, - ), - mostrecent=dict( - title=_('Most recent'), - fields=['-_created'], - default_order='desc', - order=1, - ), -)) +INDEXES = ['documents', 'organisations', 'users', 'deposits'] + +RECORDS_REST_SORT_OPTIONS = {} +for index in INDEXES: + RECORDS_REST_SORT_OPTIONS[index] = { + 'mostrecent': { + 'title': _('Most recent'), + 'fields': ['-_created'], + 'default_order': 'desc', + 'order': 1, + }, + 'bestmatch': { + 'title': _('Best match'), + 'fields': ['-_score'], + 'default_order': 'asc', + 'order': 2, + } + } """Setup sorting options.""" -RECORDS_REST_DEFAULT_SORT = dict(documents=dict( - query='bestmatch', - noquery='mostrecent', -), ) +RECORDS_REST_DEFAULT_SORT = {} +for index in INDEXES: + RECORDS_REST_DEFAULT_SORT[index] = { + 'query': 'bestmatch', + 'noquery': 'mostrecent' + } """Set default sorting options.""" RECORDS_FILES_REST_ENDPOINTS = { diff --git a/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json b/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json index b88ea243..5b72f605 100644 --- a/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json +++ b/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json @@ -238,6 +238,12 @@ "type": "keyword" } } + }, + "_created": { + "type": "date" + }, + "_updated": { + "type": "date" } } }