Skip to content

Commit fe434d9

Browse files
zubeydecivelekzzacharo
authored andcommitted
facets: add collection facet
1 parent 19abce8 commit fe434d9

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

cds/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,21 @@ def _parse_env_bool(var_name, default=None):
812812
"language": {
813813
"terms": {"field": "language.untouched"},
814814
},
815+
"collections": {
816+
"terms": {
817+
"field": "collections",
818+
"size": 50,
819+
"order": {"_key": "asc"},
820+
# Include if the collection term contains '::'.
821+
**(
822+
{"include": r".*::.*"}
823+
),
824+
# Exclude if the collection term contains two '::' (3-level paths like A::B::C).
825+
**(
826+
{"exclude": r".*::.*::.*"}
827+
),
828+
},
829+
},
815830
"years": {
816831
"date_histogram": {
817832
"field": "date",
@@ -826,6 +841,7 @@ def _parse_env_bool(var_name, default=None):
826841
"category": terms_filter("category.untouched"),
827842
"type": terms_filter("type.untouched"),
828843
"language": terms_filter("language"),
844+
"collections": terms_filter("collections"),
829845
"years": range_filter("date", format="yyyy", end_date_math="/y"),
830846
},
831847
}

cds/modules/search_ui/static/templates/cds_search_ui/facets.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ <h2 class="text-capitalize f8 mt-5"><b>{{ key }}</b></h2>
88
class="cds-facets-item-link"
99
ng-class="{'cds-facets-item-link-checked': values.indexOf(item.key) > -1}"
1010
ng-click="handleClick(key, item.key)">
11-
{{ (key === 'language') ? (item.key | isoToLanguage) : item.key }}
11+
{{
12+
(key === 'language') ? (item.key | isoToLanguage) :
13+
(key === 'collections') ? (item.key | collectionLabel) :
14+
item.key
15+
}}
1216
<span class="cds-facets-item-link-counter pull-right fw-b">
1317
<span ng-show="values.indexOf(item.key) > -1">
1418
<i class="fa fa-remove"></i>

cds/modules/theme/assets/bootstrap3/js/cds/module.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,15 @@ app.filter("isoToLanguage", [
643643
},
644644
]);
645645

646+
// Filter to translate collection keys to display labels
647+
app.filter("collectionLabel", function () {
648+
return function (key) {
649+
if (!key) return key;
650+
const strKey = String(key);
651+
return strKey.includes("::") ? strKey.split("::").pop() : strKey;
652+
};
653+
});
654+
646655
app.filter("format_relation_resource_type", function () {
647656
return function (input) {
648657
if (!input) return "";

0 commit comments

Comments
 (0)