From 4c288561b03ff40885a922f06d50a1b39046b146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=BCbeyde=20Civelek?= Date: Tue, 21 Apr 2026 18:47:27 +0200 Subject: [PATCH] facets: add collection facet --- cds/config.py | 16 ++++++++++++++++ .../static/templates/cds_search_ui/facets.html | 6 +++++- .../theme/assets/bootstrap3/js/cds/module.js | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cds/config.py b/cds/config.py index 12425a107..322946180 100644 --- a/cds/config.py +++ b/cds/config.py @@ -812,6 +812,21 @@ def _parse_env_bool(var_name, default=None): "language": { "terms": {"field": "language.untouched"}, }, + "collections": { + "terms": { + "field": "collections", + "size": 50, + "order": {"_key": "asc"}, + # Include if the collection term contains '::'. + **( + {"include": r".*::.*"} + ), + # Exclude if the collection term contains two '::' (3-level paths like A::B::C). + **( + {"exclude": r".*::.*::.*"} + ), + }, + }, "years": { "date_histogram": { "field": "date", @@ -826,6 +841,7 @@ def _parse_env_bool(var_name, default=None): "category": terms_filter("category.untouched"), "type": terms_filter("type.untouched"), "language": terms_filter("language"), + "collections": terms_filter("collections"), "years": range_filter("date", format="yyyy", end_date_math="/y"), }, } diff --git a/cds/modules/search_ui/static/templates/cds_search_ui/facets.html b/cds/modules/search_ui/static/templates/cds_search_ui/facets.html index 8f53cbad6..8652c2485 100644 --- a/cds/modules/search_ui/static/templates/cds_search_ui/facets.html +++ b/cds/modules/search_ui/static/templates/cds_search_ui/facets.html @@ -8,7 +8,11 @@

{{ key }}

class="cds-facets-item-link" ng-class="{'cds-facets-item-link-checked': values.indexOf(item.key) > -1}" ng-click="handleClick(key, item.key)"> - {{ (key === 'language') ? (item.key | isoToLanguage) : item.key }} + {{ + (key === 'language') ? (item.key | isoToLanguage) : + (key === 'collections') ? (item.key | collectionLabel) : + item.key + }} diff --git a/cds/modules/theme/assets/bootstrap3/js/cds/module.js b/cds/modules/theme/assets/bootstrap3/js/cds/module.js index 3946d33ba..f4ff805d9 100644 --- a/cds/modules/theme/assets/bootstrap3/js/cds/module.js +++ b/cds/modules/theme/assets/bootstrap3/js/cds/module.js @@ -643,6 +643,15 @@ app.filter("isoToLanguage", [ }, ]); +// Filter to translate collection keys to display labels +app.filter("collectionLabel", function () { + return function (key) { + if (!key) return key; + const strKey = String(key); + return strKey.includes("::") ? strKey.split("::").pop() : strKey; + }; +}); + app.filter("format_relation_resource_type", function () { return function (input) { if (!input) return "";