Skip to content

Commit

Permalink
Add more search results scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jan 10, 2024
1 parent 1a26088 commit 32a04c5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
brand_icon_from_url,
headings_list,
pretty_date,
pretty_number,
slugify,
tna_html,
)
Expand Down Expand Up @@ -44,6 +45,7 @@ def create_app(config_class=Config):
app.add_template_filter(tna_html)
app.add_template_filter(slugify)
app.add_template_filter(pretty_date)
app.add_template_filter(pretty_number)
app.add_template_filter(article_supertitle)
app.add_template_filter(article_type)
app.add_template_filter(brand_icon_from_url)
Expand Down
2 changes: 2 additions & 0 deletions app/lib/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def generate_new_page_query_string(args, page):
def pagination_object(
current_page, total_pages, current_args, boundaries=1, around=1
):
if total_pages == 0:
return {}
current_page = int(current_page)
pagination_object = {}
pagination_object["items"] = [
Expand Down
4 changes: 4 additions & 0 deletions app/lib/template_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def pretty_date(s):
return new_date


def pretty_number(s):
return f"{s:,}"


def article_supertitle(s):
if s == "articles.ArticlePage":
return "The story of"
Expand Down
18 changes: 16 additions & 2 deletions app/templates/search/catalogue.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%- from 'macros/feedback.html' import feedback -%}
{%- from 'search/elements/sort-view.html' import sortView -%}

{% block pageTitle %}Search our catalogue - {{ super() }}{% endblock %}
{% block pageTitle %}{% if results %}{{ results.count }} results - {% endif %}{{ super() }}{% endblock %}

{% block skipLink %}
{{ tnaSkipLink({
Expand All @@ -22,12 +22,13 @@
{% block content %}
{% set show_tabs = True %}
{% include 'search/elements/header.html' %}
{% if results.count %}
<section class="tna-section tna-container tna-!--no-padding-bottom">
<div class="tna-column tna-column--full">
<p>Catalogue results for records held at The National Archives that match your search term.</p>
{% include 'search/elements/buckets.html' %}
</div>
{{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our website') }}
{{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our records') }}
</section>
<section class="tna-container">
<div id="search-filters" class="tna-column tna-column--width-1-4 tna-column--width-1-3-medium tna-column--full-small tna-column--full-tiny etna-search-sidebar tna-!--padding-top-l">
Expand Down Expand Up @@ -327,6 +328,19 @@ <h3 class="tna-heading-m">
<input type="hidden" value="{{ page }}" name="page" form="search-form">
{% endif %}
</section>
{% else %}
<section class="tna-section tna-container tna-!--no-padding-bottom">
<div class="tna-column tna-column--width-2-3 tna-column--width-5-6-medium tna-column--full-small tna-column--full-tiny">
<h2 class="tna-heading-l">We did not find any results for your search</h2>
<p>Some record descriptions are much less detailed than others, so you may not find what you are looking for using a simple keyword search.</p>
<ul class="tna-ul">
<li>Try different spellings or search terms</li>
<li>Use the advanced search options such as the &quot;AND&quot;, &quot;OR&quot; and &quot;NOT&quot; operators</li>
<li>Look at our research guides for search tips</li>
</ul>
</div>
</section>
{% endif %}
{{ feedback() }}
{% endblock %}

Expand Down
4 changes: 2 additions & 2 deletions app/templates/search/elements/sort-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{% macro sortView(query, results_count, result_range_min, result_range_max, bucket_name) %}
<div class="tna-column tna-column--flex-1 tna-column--full-small tna-column--full-tiny tna-!--margin-top-m">
{% if query %}
<p>Showing {{ result_range_min }}&ndash;{{ result_range_max }} of {{ results_count }} results for &quot;{{ query or '' }}&quot; in {{ bucket_name }}</p>
<p>Showing {{ result_range_min }}&ndash;{{ result_range_max }} of {{ results_count | pretty_number }} results for &quot;{{ query or '' }}&quot; in {{ bucket_name }}</p>
{% else %}
<p>Showing {{ result_range_min }}&ndash;{{ result_range_max }} of {{ results_count }} results in {{ bucket_name }}</p>
<p>Showing {{ result_range_min }}&ndash;{{ result_range_max }} of {{ results_count | pretty_number }} results in {{ bucket_name }}</p>
{% endif %}
</div>
<div class="tna-column tna-column--flex-1-small tna-column--full-tiny etna-search-sort-view tna-!--margin-top-m">
Expand Down
11 changes: 10 additions & 1 deletion app/templates/search/website.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
{%- from 'macros/feedback.html' import feedback -%}
{%- from 'search/elements/sort-view.html' import sortView -%}

{% block pageTitle %}Search our website - {{ super() }}{% endblock %}
{% block pageTitle %}{% if results %}{{ results.count }} results - {% endif %}{{ super() }}{% endblock %}

{% block content %}
{% set show_tabs = True %}
{% include 'search/elements/header.html' %}
{% if results.count %}
<section class="tna-container">
{{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our website') }}
{% set selected_filters = [] %}
Expand Down Expand Up @@ -146,6 +147,14 @@ <h1 class="tna-hgroup__title">
<input type="hidden" value="{{ page }}" name="page" form="search-form">
{% endif %}
</section>
{% else %}
<section class="tna-section tna-container tna-!--no-padding-bottom">
<div class="tna-column tna-column--width-2-3 tna-column--width-5-6-medium tna-column--full-small tna-column--full-tiny">
<h2 class="tna-heading-l">We did not find any results for your search</h2>
<p>Try again with different spellings or search terms or view <a href="{{ url_for('search.website') }}">all website results</a>.</p>
</div>
</section>
{% endif %}
{{ feedback() }}
{% endblock %}

Expand Down

0 comments on commit 32a04c5

Please sign in to comment.