Skip to content

Commit

Permalink
Add scope and full text search to frontend (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Nov 3, 2023
1 parent 4bff60a commit 772546e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 16 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ assets/upload/*
!assets/upload/index.html

*_dev
snippets

# profiler
*.profile
Expand Down
18 changes: 17 additions & 1 deletion apps/cms/templatetags/readux_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@

register = Library()


@register.filter_function
def order_by(queryset, args):
args = [x.strip() for x in args.split(',')]
args = [x.strip() for x in args.split(",")]
return queryset.order_by(*args)


@register.filter
def dict_item(dictionary, key):
"""'Template filter to allow accessing dictionary value by variable key.
Example use::
{{ mydict|dict_item:keyvar }}
"""
# adapted from Princeton-CDH/geniza project https://github.com/Princeton-CDH/geniza/
try:
return dictionary[key]
except AttributeError:
# fail silently if something other than a dict is passed
return None
39 changes: 38 additions & 1 deletion apps/static/css/project.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions apps/templates/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,21 @@ <h1 class="uk-heading-medium uk-text-center">Search</h1>
accept-charset="utf-8"
>
<div class="uk-form uk-width-1-1">
<fieldset class="uk-margin uk-width-1-1">
<div class="uk-inline uk-width-1-1">
<span class="uk-form-icon" uk-icon="icon: search" aria-label="search"></span>
{{ form.q }}
<fieldset class="uk-margin uk-width-1-1 scope-and-keyword">
<div class="scope">
{{ form.scope }}
</div>
<div class="keyword">
<div class="uk-inline uk-width-1-1">
<span class="uk-form-icon" uk-icon="icon: search" aria-label="search"></span>
{{ form.q }}
</div>
</div>
<span class="uk-text-small">
Search for individual whole keywords. Multiple words will be searched as
'or' (e.g. Rome London = Rome or London).
</span>
</fieldset>
<span class="uk-text-small">
Search for individual whole keywords. Multiple words will be searched as
'or' (e.g. Rome London = Rome or London).
</span>
<fieldset class="uk-margin uk-width-1-1">
<div class="uk-form-label">{{ form.sort.label }}</div>
{{ form.sort }}
Expand Down
29 changes: 24 additions & 5 deletions apps/templates/snippets/volume_result.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load readux_templatetags %}

<li class="uk-width-1-1@m uk-margin-small">
<h4>
Expand All @@ -7,7 +8,7 @@ <h4>
class="nav-link"
href="{% url 'volumeall' volume.pid %}"
>
{% if volume.meta.highlight.label %}
{% if 'highlight' in volume.meta and volume.meta.highlight.label %}
{% for fragment in volume.meta.highlight.label %}
{{ fragment|safe }}
{% endfor %}
Expand All @@ -16,7 +17,7 @@ <h4>
{% endif %}
</a>
{% else %}
{% if volume.meta.highlight.label %}
{% if 'highlight' in volume.meta and volume.meta.highlight.label %}
{% for fragment in volume.meta.highlight.label %}
{{ fragment|safe }}
{% endfor %}
Expand All @@ -34,7 +35,7 @@ <h4>
<dt>Author{{volume.authors|pluralize}}</dt>
<dd>
<ul class="uk-margin-remove">
{% if volume.meta.highlight.author %}
{% if 'highlight' in volume.meta and volume.meta.highlight.author %}
{% for fragment in volume.meta.highlight.author %}
{{ fragment|safe }}
{% endfor %}
Expand Down Expand Up @@ -63,7 +64,7 @@ <h4>
{% if volume.summary %}
<dt>Summary</dt>
<dd class="result-volume-summary">
{% if volume.meta.highlight.summary %}
{% if 'highlight' in volume.meta and volume.meta.highlight.summary %}
{% for fragment in volume.meta.highlight.summary %}
{{ fragment|safe }}
{% endfor %}
Expand All @@ -72,5 +73,23 @@ <h4>
{% endif %}
</dd>
{% endif %}
{% if 'inner_hits' in volume.meta and volume.meta.inner_hits.canvases.hits.total.value %}
<dt>Full Text</dt>
{% for canvas in volume.meta.inner_hits.canvases %}
<dd class="result-page">
<a href="{% url 'page' volume=volume.pid page=canvas.pid %}">
<span class="page-number">{{ canvas.position|add:1 }}</span>
{% if canvas.thumbnail %}<img src="{{ canvas.thumbnail }}" loading="lazy" />{% endif %}
{% if canvas.meta.highlight %}
<ul class="highlights">
{% for fragment in canvas.meta.highlight|dict_item:"canvas_set.result" %}
<li class="result-volume-summary">{{ fragment|safe }}</li>
{% endfor %}
</ul>
{% endif %}
</a>
</dd>
{% endfor %}
{% endif %}
</dl>
</li>
</li>

0 comments on commit 772546e

Please sign in to comment.