Skip to content

Commit

Permalink
config: allow request search configuration
Browse files Browse the repository at this point in the history
* closes #384
  • Loading branch information
egabancho authored and fenekku committed Jun 24, 2024
1 parent fa4c815 commit b1b126a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
22 changes: 22 additions & 0 deletions invenio_requests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@
}
"""Invenio requests ui endpoints."""

REQUESTS_SEARCH = {
"facets": ["type", "status"],
"sort": ["bestmatch", "newest", "oldest"],
}
"""Requests search default configuration."""

REQUESTS_SORT_OPTIONS = {
"bestmatch": dict(
title=_("Best match"),
fields=["_score"], # search defaults to desc on `_score` field
),
"newest": dict(
title=_("Newest"),
fields=["-created"],
),
"oldest": dict(
title=_("Oldest"),
fields=["created"],
),
}
"""Definitions of available request sort options."""

REQUESTS_FACETS = {
"type": {
"facet": facets.type,
Expand Down
16 changes: 13 additions & 3 deletions invenio_requests/services/requests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"""Requests service configuration."""

from invenio_records_resources.services import RecordServiceConfig, SearchOptions
from invenio_records_resources.services.base.config import ConfiguratorMixin, FromConfig
from invenio_records_resources.services.base.config import (
ConfiguratorMixin,
FromConfig,
FromConfigSearchOptions,
SearchOptionsMixin,
)
from invenio_records_resources.services.records.links import pagination_links

from invenio_requests.services.requests import facets
Expand Down Expand Up @@ -39,7 +44,7 @@ def _is_action_available(request, context):
return RequestActions.can_execute(request, action) and permission.allows(identity)


class RequestSearchOptions(SearchOptions):
class RequestSearchOptions(SearchOptions, SearchOptionsMixin):
"""Search options."""

params_interpreters_cls = SearchOptions.params_interpreters_cls + [
Expand All @@ -66,7 +71,12 @@ class RequestsServiceConfig(RecordServiceConfig, ConfiguratorMixin):
)
result_item_cls = RequestItem
result_list_cls = RequestList
search = RequestSearchOptions
search = FromConfigSearchOptions(
config_key="REQUESTS_SEARCH",
sort_key="REQUESTS_SORT_OPTIONS",
facet_key="REQUESTS_FACETS",
search_option_cls=RequestSearchOptions,
)

# request-specific configuration
record_cls = Request # needed for model queries
Expand Down

0 comments on commit b1b126a

Please sign in to comment.