diff --git a/geniza/corpus/forms.py b/geniza/corpus/forms.py index 48c49f715..11bd56d7f 100644 --- a/geniza/corpus/forms.py +++ b/geniza/corpus/forms.py @@ -162,7 +162,7 @@ class DocumentSearchForm(RangeForm): widget=forms.TextInput( attrs={ # Translators: placeholder for keyword search input - "placeholder": _("search by keyword"), + "placeholder": _("Search all fields by keyword"), # Translators: accessible label for keyword search input "aria-label": _("Keyword or Phrase"), "type": "search", @@ -207,9 +207,9 @@ class DocumentSearchForm(RangeForm): required=False, widget=SelectWithDisabled, ) - # Translators: label for filter documents by date range docdate = RangeField( - label=_("Document Dates (CE)"), + # Translators: label for filter documents by date range + label=_("Dates"), required=False, widget=YearRangeWidget( attrs={"size": 4, "data-action": "input->search#update"}, @@ -218,23 +218,23 @@ class DocumentSearchForm(RangeForm): doctype = FacetChoiceField( # Translators: label for document type search form filter - label=_("Document Type"), + label=_("Document type"), ) has_image = BooleanFacetField( # Translators: label for "has image" search form filter - label=_("Has Image"), + label=_("Image"), ) has_transcription = BooleanFacetField( # Translators: label for "has transcription" search form filter - label=_("Has Transcription"), + label=_("Transcription"), ) has_translation = BooleanFacetField( # Translators: label for "has translation" search form filter - label=_("Has Translation"), + label=_("Translation"), ) has_discussion = BooleanFacetField( # Translators: label for "has discussion" search form filter - label=_("Has Discussion"), + label=_("Discussion"), ) # mapping of solr facet fields to form input @@ -258,6 +258,14 @@ def __init__(self, data=None, *args, **kwargs): {"label": self.SORT_CHOICES[0][1], "disabled": True}, ) + def get_translated_label(self, field, label): + """Lookup translated label via db model object when applicable; + handle Person.gender as a special case; and otherwise just return the label""" + if field == "type" or field == "doctype": + # for doctype, label should be translated, so use doctype object + return DocumentType.objects_by_label.get(label, _("Unknown type")) + return label + def filters_active(self): """Check if any filters are active; returns true if form fields other than sort or q are set""" if self.is_valid(): @@ -276,20 +284,10 @@ def set_choices_from_facets(self, facets): # populate facet field choices from current facets for key, facet_dict in facets.items(): # restructure dict to set values of each key to tuples of (label, count) - if key == "type": - # for doctype, label should be translated, so use doctype object - facet_dict = { - label: ( - DocumentType.objects_by_label.get(label, _("Unknown type")), - count, - ) - for (label, count) in facet_dict.items() - } - else: - # for other formfields, label == facet name - facet_dict = { - label: (label, count) for (label, count) in facet_dict.items() - } + facet_dict = { + label: (self.get_translated_label(key, label), count) + for (label, count) in facet_dict.items() + } # use field from facet fields map or else field name as is formfield = self.solr_facet_fields.get(key, key) # for each facet, set the corresponding choice field diff --git a/geniza/corpus/models.py b/geniza/corpus/models.py index da6f16600..940bb93f9 100644 --- a/geniza/corpus/models.py +++ b/geniza/corpus/models.py @@ -1159,6 +1159,8 @@ def prep_index_chunk(cls, chunk): "languages", "log_entries", "dating_set", + "persondocumentrelation_set", + "documentplacerelation_set", Prefetch( "textblock_set", queryset=TextBlock.objects.select_related( @@ -1237,6 +1239,7 @@ def index_data(self): "old_pgpids_is": self.old_pgpids, "language_code_s": self.primary_lang_code, "language_script_s": self.primary_script, + "language_name_ss": [str(l) for l in self.languages.all()], # use image info link without trailing info.json to easily convert back to iiif image client # NOTE: if/when piffle supports initializing from full image uris, we could simplify this # code to index the full image url, with rotation overrides applied @@ -1247,6 +1250,8 @@ def index_data(self): "iiif_labels_ss": [img["label"] for img in images], "iiif_rotations_is": [img["rotation"] for img in images], "has_image_b": len(images) > 0, + "people_count_i": self.persondocumentrelation_set.count(), + "places_count_i": self.documentplacerelation_set.count(), } ) @@ -1283,11 +1288,13 @@ def index_data(self): fn.doc_relation ) - # make sure digital editions are also counted as editions, - # whether or not there is a separate edition footnote + # make sure digital editions/translations are also counted, + # whether or not there is a separate edition/translation footnote for source, doc_relations in source_relations.items(): if Footnote.DIGITAL_EDITION in doc_relations: source_relations[source].add(Footnote.EDITION) + if Footnote.DIGITAL_TRANSLATION in doc_relations: + source_relations[source].add(Footnote.TRANSLATION) # flatten sets of relations by source into a list of relations for relation in list(chain(*source_relations.values())): diff --git a/geniza/corpus/solr_queryset.py b/geniza/corpus/solr_queryset.py index f4b7b47c1..134e2ba93 100644 --- a/geniza/corpus/solr_queryset.py +++ b/geniza/corpus/solr_queryset.py @@ -46,6 +46,7 @@ class DocumentSolrQuerySet(AliasedSolrQuerySet): "type": "type_s", "status": "status_s", "shelfmark": "shelfmark_s", # string version for display + "shelfmarks": "fragment_shelfmark_ss", "document_date": "document_date_t", # text version for search & display "original_date_t": "original_date", "collection": "collection_ss", @@ -65,6 +66,7 @@ class DocumentSolrQuerySet(AliasedSolrQuerySet): "transcription": "text_transcription", "language_code": "language_code_s", "language_script": "language_script_s", + "languages": "language_name_ss", "translation": "text_translation", "translation_language_code": "translation_language_code_s", "translation_language_direction": "translation_language_direction_s", @@ -79,6 +81,8 @@ class DocumentSolrQuerySet(AliasedSolrQuerySet): "old_shelfmark_t": "old_shelfmark_t", "transcription_nostem": "transcription_nostem", "description_nostem": "description_nostem", + "related_people": "people_count_i", + "related_places": "places_count_i", } # regex to convert field aliases used in search to actual solr fields @@ -254,6 +258,18 @@ def get_result_document(self, doc): _("Unknown type"), ) + if doc.get("shelfmarks"): + doc["related_documents"] = ( + DocumentSolrQuerySet() + .filter("NOT pgpid_i:%d" % doc["pgpid"]) + .filter( + fragment_shelfmark_ss__in=[ + '"%s"' % shelfmark for shelfmark in doc["shelfmarks"] + ] + ) + .count() + ) + return doc def get_highlighting(self): diff --git a/geniza/corpus/templates/corpus/document_list.html b/geniza/corpus/templates/corpus/document_list.html index 3babcfccd..ccee49427 100644 --- a/geniza/corpus/templates/corpus/document_list.html +++ b/geniza/corpus/templates/corpus/document_list.html @@ -5,7 +5,7 @@ {% block meta_description %}{{ page_description }}{% endblock meta_description %} {% block main %} -

{{ page_title }}

+

{{ page_title }}

{% render_field form.q data-search-target="query" data-action="input->search#autoUpdateSort change->search#update" %} @@ -14,60 +14,82 @@

{{ page_title }}

{% translate 'Submit search' as search_label %}
- - - {% translate "Filters" %} - - +
+ + + {% translate "Filters" %} + {% if applied_filters %} + {{ applied_filters|length }} + {% endif %} + + {% if applied_filters %} + {# convenient unapply filter buttons; aria role set to presentation as functionality duplicated below #} + + + {% endif %} +
+ - -
- - {% render_field form.sort id="sort" data-search-target="sort" data-action="input->search#update" %} - {# caret icon for ; since we also have the select element, role=presentation #} + +
+ +
    + {% for document in documents %} + {% include "corpus/snippets/document_result.html" %} + {% endfor %} +
+ {% if is_paginated %} + {% include "corpus/snippets/pagination.html" %} {% endif %} - {% endif %} - + +
{% endblock main %} diff --git a/geniza/corpus/templates/corpus/snippets/document_result.html b/geniza/corpus/templates/corpus/snippets/document_result.html index 36cd9e270..33ac9bad7 100644 --- a/geniza/corpus/templates/corpus/snippets/document_result.html +++ b/geniza/corpus/templates/corpus/snippets/document_result.html @@ -7,14 +7,13 @@ {{ forloop.counter0|add:start_adjust }} {% endwith %} + {# title #} +

+ {# type and shelfmark #} + {{ document.type }} + {{ document.shelfmark|shelfmark_wrap }} +

- {# title #} -

- {# type and shelfmark #} - {{ document.type }} - {{ document.shelfmark|shelfmark_wrap }} -

- {# metadata #}
{% if document.document_date %} @@ -27,21 +26,17 @@

{% endif %} - {% with document_highlights=highlighting|dict_item:document.id %} - {% if document_highlights.old_shelfmark %} - {# Translators: label for historical/old shelfmark on document fragments #} -
{% translate "Historical shelfmark" %}
-
{{ document_highlights.old_shelfmark|striptags }}
- {% endif %} - {% endwith %} - {# Translators: Date document was first added to the PGP #} -
{% translate "In PGP since" %}
- {# Translators: label for unknown date for date added to PGP #} - {% translate "unknown" as unknown %} -
{{ document.input_year|default:unknown }}
- {# NOTE: Intentionally left untranslated #} -
PGP ID
-
{{ document.pgpid }}
+ {% if document.languages|length %} +
+ {# Translators: Primary language label #} + {% blocktranslate count counter=document.languages|length trimmed %} + Primary language + {% plural %} + Primary languages + {% endblocktranslate %} +
+
{{ document.languages|join:", " }}
+ {% endif %}

{# description #} @@ -94,7 +89,41 @@

{% endif %} {% endwith %} - {# scholarship records #} + {# related documents and entities #} + {% if document.related_documents or document.related_people or document.related_places %} + + {% endif %} + + {# tags #} + {% if document.tags %} + {# Translators: label for tags on a document #} +

{% translate 'Tags' %}

+ + {% endif %} + + {# scholarship records #}

{% if document.scholarship_count %} {% if document.num_editions %} @@ -131,44 +160,53 @@

{% translate 'No Scholarship Records' %} {% endif %}

+

- {# tags #} - {% if document.tags %} - {# Translators: label for tags on a document #} -

{% translate 'Tags' %}

-