Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: allow request search configuration #386

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading