diff --git a/apps/iiif/manifests/documents.py b/apps/iiif/manifests/documents.py index 5c372013..87ef093d 100644 --- a/apps/iiif/manifests/documents.py +++ b/apps/iiif/manifests/documents.py @@ -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 diff --git a/apps/readux/forms.py b/apps/readux/forms.py index 1179f59d..66252e8d 100644 --- a/apps/readux/forms.py +++ b/apps/readux/forms.py @@ -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(" ", "_") diff --git a/apps/readux/views.py b/apps/readux/views.py index 23b542fc..1842a4d4 100644 --- a/apps/readux/views.py +++ b/apps/readux/views.py @@ -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), @@ -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) @@ -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: diff --git a/config/settings/local.dst b/config/settings/local.dst index b95c6da4..a229c2ce 100644 --- a/config/settings/local.dst +++ b/config/settings/local.dst @@ -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, # }, # }