Skip to content

Commit

Permalink
Merge 23f6ab4 into 051b75b
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Délèze committed Aug 23, 2021
2 parents 051b75b + 23f6ab4 commit 375707c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 24 deletions.
94 changes: 74 additions & 20 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def _(x):
SECURITY_RESET_PASSWORD_TEMPLATE = 'sonar/accounts/reset_password.html'
SECURITY_REGISTER_USER_TEMPLATE = 'sonar/accounts/signup.html'
SECURITY_EMAIL_SUBJECT_PASSWORD_RESET = _('SONAR password reset')
SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE = _('Your SONAR password has been reset')
SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE = _(
'Your SONAR password has been reset')

RECORDS_UI_ENDPOINTS = {
'doc': {
Expand Down Expand Up @@ -504,16 +505,16 @@ def _(x):
RECORDS_REST_FACETS = {
'documents':
dict(aggs=dict(
sections=dict(terms=dict(field='sections',
size=DEFAULT_AGGREGATION_SIZE)),
sections=dict(
terms=dict(field='sections', size=DEFAULT_AGGREGATION_SIZE)),
organisation=dict(terms=dict(field='organisation.pid',
size=DEFAULT_AGGREGATION_SIZE)),
language=dict(
terms=dict(field='language.value', size=DEFAULT_AGGREGATION_SIZE)),
subject=dict(
terms=dict(field='facet_subjects', size=DEFAULT_AGGREGATION_SIZE)),
collection=dict(terms=dict(field='collections.pid',
size=DEFAULT_AGGREGATION_SIZE)),
size=DEFAULT_AGGREGATION_SIZE)),
document_type=dict(
terms=dict(field='documentType', size=DEFAULT_AGGREGATION_SIZE)),
controlled_affiliation=dict(
Expand Down Expand Up @@ -595,31 +596,84 @@ def _(x):
}
"""REST search facets."""

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,
RECORDS_REST_SORT_OPTIONS = {
'documents': {
'relevance': {
'fields': ['-_score'],
},
'bestmatch': {
'title': _('Best match'),
'newest': {
'fields': ['-_created']
},
'oldest': {
'fields': ['_created']
},
'title': {
'fields': ['title.mainTitle.value.raw']
}
},
'users': {
'relevance': {
'fields': ['-_score'],
'default_order': 'asc',
'order': 2,
},
'newest': {
'fields': ['-_created']
},
'oldest': {
'fields': ['_created']
},
'name': {
'fields': ['full_name.raw']
}
},
'organisations': {
'relevance': {
'fields': ['-_score'],
},
'newest': {
'fields': ['-_created']
},
'oldest': {
'fields': ['_created']
},
'name': {
'fields': ['name.raw']
}
},
'collections': {
'relevance': {
'fields': ['-_score'],
},
'newest': {
'fields': ['-_created']
},
'oldest': {
'fields': ['_created']
},
'name': {
'fields': ['name.value.raw']
}
},
'deposits': {
'relevance': {
'fields': ['-_score'],
},
'newest': {
'fields': ['-_created']
},
'oldest': {
'fields': ['_created']
}
}
}
"""Setup sorting options."""

INDEXES = ['documents', 'organisations', 'users', 'deposits']

RECORDS_REST_DEFAULT_SORT = {}
for index in INDEXES:
RECORDS_REST_DEFAULT_SORT[index] = {
'query': 'bestmatch',
'noquery': 'mostrecent'
'query': 'relevance',
'noquery': 'newest'
}
"""Set default sorting options."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"raw": {
"type": "keyword"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@
"type": "object",
"properties": {
"value": {
"type": "text"
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"language": {
"type": "keyword"
Expand Down Expand Up @@ -554,7 +559,7 @@
"type": "text",
"fields": {
"raw": {
"type": "keyword"
"type": "keyword"
},
"suggest": {
"type": "completion",
Expand All @@ -566,7 +571,7 @@
"type": "text",
"fields": {
"raw": {
"type": "keyword"
"type": "keyword"
},
"suggest": {
"type": "completion",
Expand All @@ -578,7 +583,7 @@
"type": "text",
"fields": {
"raw": {
"type": "keyword"
"type": "keyword"
},
"suggest": {
"type": "completion",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
"description": {
"type": "text"
},
"name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"code": {
"type": "keyword"
},
Expand Down
3 changes: 3 additions & 0 deletions sonar/modules/users/mappings/v7/users/user-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"suggest": {
"type": "completion",
"analyzer": "default"
},
"raw": {
"type": "keyword"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"raw": {
"type": "keyword"
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions sonar/resources/projects/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class RecordServiceConfig(BaseRecordServiceConfig):
permission_policy_cls = RecordPermissionPolicy
record_cls = Record
result_list_cls = RecordList
search_sort_default = 'relevance'
search_sort_default_no_query = 'newest'
search_sort_options = {
'relevance': {
'fields': ['_score'],
},
'name': {
'fields': ['metadata.name.raw']
},
'newest': {
'fields': ['-created']
},
'oldest': {
'fields': ['created']
}
}
search_facets_options = {
'aggs': {
'user': {
Expand Down

0 comments on commit 375707c

Please sign in to comment.