Skip to content

Commit

Permalink
Merge pull request ecds#1112 from ecds/feature/disable-custom-meta-facet
Browse files Browse the repository at this point in the history
Manual configuration for which custom meta fields are facets
  • Loading branch information
blms authored Nov 11, 2024
2 parents 62192b9 + a609a6b commit 5bac6f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion apps/iiif/manifests/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def prepare_metadata(self, instance):
and isinstance(settings.CUSTOM_METADATA, dict)
):
# should be a dict like {meta_key: {"multi": bool, "separator": str}}
for key, opts in settings.CUSTOM_METADATA.items():
for key, opts in filter(
lambda item: item[1].get("faceted", False), # filter to only faceted fields
settings.CUSTOM_METADATA.items(),
):
val = None
# each key in CUSTOM_METADATA dict should be a metadata key.
# however, instance.metadata will generally be a list rather than a dict: it's a
Expand Down
8 changes: 6 additions & 2 deletions apps/readux/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ def __init__(self, *args, **kwargs):
and hasattr(settings, "CUSTOM_METADATA")
and isinstance(settings.CUSTOM_METADATA, dict)
):
# should be a dict like {meta_key: {"multi": bool, "separator": str}}
for key in settings.CUSTOM_METADATA.keys():
# should be a dict like {meta_key: {"multi": bool, "separator": str, "faceted": bool}}
for key in [
k
for k in settings.CUSTOM_METADATA.keys()
if settings.CUSTOM_METADATA[k].get("faceted", False)
]:
self.fields[
# use django-friendly form field names
key.casefold().replace(" ", "_")
Expand Down
13 changes: 11 additions & 2 deletions apps/readux/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ def __init__(self, *args, **kwargs):
and hasattr(settings, "CUSTOM_METADATA")
and isinstance(settings.CUSTOM_METADATA, dict)
):
for key in settings.CUSTOM_METADATA.keys():
for key in [
k
for k in settings.CUSTOM_METADATA.keys()
if settings.CUSTOM_METADATA[k].get("faceted", False)
]:
self.facets.append((key, NestedFacet(
"metadata",
TermsFacet(field=f"metadata.{key}", size=2000, min_doc_count=1),
Expand Down Expand Up @@ -351,6 +355,7 @@ def get_context_data(self, **kwargs):
# use django-friendly form field names
key.casefold().replace(" ", "_")
for key in settings.CUSTOM_METADATA.keys()
if settings.CUSTOM_METADATA[key].get("faceted", False) == True
]
if hasattr(settings, "CUSTOM_METADATA")
and isinstance(settings.CUSTOM_METADATA, dict)
Expand Down Expand Up @@ -512,7 +517,11 @@ def get_queryset(self):
if hasattr(settings, "CUSTOM_METADATA") and isinstance(
settings.CUSTOM_METADATA, dict
):
for key in settings.CUSTOM_METADATA.keys():
for key in [
k
for k in settings.CUSTOM_METADATA.keys()
if settings.CUSTOM_METADATA[k].get("faceted", False)
]:
field_name = key.casefold().replace(" ", "_")
meta_filter = form_data.get(field_name) or ""
if meta_filter:
Expand Down
17 changes: 13 additions & 4 deletions config/settings/local.dst
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,31 @@ LOGGING = {
ELASTICSEARCH_DSL['default']['hosts'] = 'user:pass@localhost:9200'
INDEX_PREFIX = "readux_test"

# Custom faceted metadata fields configuration. Must be a dict with key names
# matching exactly the ingest metadata spradsheet column names to be indexed.
# Custom metadata fields configuration. Metadata in this list will appear under
# "Advanced" in each volume's metadata. Must be a dict with key names
# matching exactly the spradsheet column names in volume ingest metadata.
# For each column, configure options for whether it should accept multiple
# values in a single record ("multi": True), and if so, what separator will be
# used ("separator": ";", semicolon by default).
# Note that these key names will also correspond to "label" names in the Manifest
# metadata list.
#
# If you would like a field to appear as a faceted search filter on the volumes
# search page, include "faceted": True for that field. If not included, or set
# False, the field will not be indexed for search. Changing this setting will
# require a search reindex (python manage.py search_index --rebuild).
#
# Note that these key names will also correspond to "label" names in each IIIF
# manifest's metadata list.
#
# Example:
# CUSTOM_METADATA = {
# "Column Name": {
# "multi": True,
# "separator": ";",
# "faceted": True,
# },
# "Other Column": {
# "multi": False,
# "faceted": False,
# },
# }

Expand Down

0 comments on commit 5bac6f6

Please sign in to comment.