Skip to content

Commit

Permalink
Revise fulltext search
Browse files Browse the repository at this point in the history
- sort by most relevant page
- no thumbnails in search (but add p. before page numbers)
- fix issue with scores for inner hits
  • Loading branch information
blms committed Nov 6, 2023
1 parent 772546e commit e262ad5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion apps/iiif/manifests/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ManifestDocument(Document):
properties={
"result": fields.TextField(analyzer=stemmer),
"position": fields.IntegerField(),
"thumbnail": fields.KeywordField(),
"pid": fields.KeywordField(),
}
) # canvas_set.result = OCR annotation text on each canvas
Expand Down
4 changes: 3 additions & 1 deletion apps/readux/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,11 @@ def get_queryset(self):
inner_hits={
"name": "canvases",
"size": 3, # max number of pages shown in full-text results
"sort": [{"canvas_set.position": {"order": "asc"}}],
"highlight": {"fields": {"canvas_set.result": {}}},
},
# sum scores if in full text only search, so vols with most hits show up first.
# if also searching metadata, use avg (default) instead, to not over-inflate.
score_mode="sum" if scope == "text" else "avg",
)
queries.append(nested_query)

Expand Down
17 changes: 10 additions & 7 deletions apps/static/css/project.css

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

5 changes: 2 additions & 3 deletions apps/templates/snippets/volume_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ <h4>
{% 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 %}
<span class="page-number">p. {{ canvas.position|add:1 }}</span>
{% 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>
<li>{{ fragment|safe }}</li>
{% endfor %}
</ul>
{% endif %}
Expand Down

0 comments on commit e262ad5

Please sign in to comment.