Enhance case search results display to include series modalities and examinations
This commit is contained in:
@@ -7,6 +7,25 @@
|
||||
<h6 class="mb-1">{{ case.title }}</h6>
|
||||
<small class="text-muted">{{ case.created_date|date:"Y-m-d" }}</small>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<small class="text-muted me-2">{% if case.author.all %}By {{ case.author.all|join:", " }}{% endif %}</small>
|
||||
{% if case.condition %}<span class="badge bg-secondary me-1">{{ case.condition.name }}</span>{% endif %}
|
||||
{% if case.presentation %}<span class="badge bg-secondary me-1">{{ case.presentation.name }}</span>{% endif %}
|
||||
{% if case.subspecialty %}<span class="badge bg-secondary">{{ case.subspecialty.name }}</span>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-1">
|
||||
{# show up to three series modalities/examinations if present #}
|
||||
{% for s in case.series.all|slice:":3" %}
|
||||
<span class="badge bg-light text-dark me-1">
|
||||
{% if s.modality %}{{ s.modality.modality }}{% endif %}
|
||||
{% if s.examination %} / {{ s.examination.examination }}{% endif %}
|
||||
</span>
|
||||
{% empty %}
|
||||
<small class="text-muted">No series</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<p class="mb-1 text-truncate">{{ case.description }}</p>
|
||||
</a>
|
||||
{% endfor %}
|
||||
|
||||
@@ -191,6 +191,45 @@ def case_search_partial(request):
|
||||
the index page. It respects the user's available cases via
|
||||
get_cases_available_to_user.
|
||||
"""
|
||||
# NOTE (search migration):
|
||||
#
|
||||
# This view currently performs simple `__icontains` lookups across Case
|
||||
# fields and related models. For better relevance and performance you can
|
||||
# migrate this to use PostgreSQL full-text search (FTS). Recommended steps:
|
||||
#
|
||||
# 1) Enable optional Postgres extensions (if you want trigram/unaccent):
|
||||
# - Add migrations: `TrigramExtension()` and optionally `UnaccentExtension()`
|
||||
# from `django.contrib.postgres.operations`.
|
||||
#
|
||||
# 2) Create a tsvector expression index (recommended) or add a
|
||||
# SearchVectorField on the Case model. Example expression index SQL:
|
||||
# CREATE INDEX CONCURRENTLY idx_case_search ON atlas_case
|
||||
# USING GIN (to_tsvector('english', coalesce(title,'') || ' ' ||
|
||||
# coalesce(description,'') || ' ' || coalesce(history,'')));
|
||||
#
|
||||
# Alternatively use a Django migration with `GinIndex` on an
|
||||
# `SearchVectorField` or a `Func` expression.
|
||||
#
|
||||
# 3) Query using django.contrib.postgres.search utilities. Example:
|
||||
# from django.contrib.postgres.search import (
|
||||
# SearchVector, SearchQuery, SearchRank
|
||||
# )
|
||||
# sv = (SearchVector('title', weight='A') +
|
||||
# SearchVector('description', weight='B') +
|
||||
# SearchVector('history', weight='C'))
|
||||
# sq = SearchQuery(q)
|
||||
# qs = Case.objects.annotate(search=sv).filter(search=sq)
|
||||
# .annotate(rank=SearchRank(F('search'), sq)).order_by('-rank')
|
||||
#
|
||||
# 4) For interactive/fuzzy typing consider pg_trgm (TrigramExtension)
|
||||
# and `TrigramSimilarity` as a fallback when FTS returns few results.
|
||||
#
|
||||
# 5) Keep in mind to re-index (or recreate indexes) when you change
|
||||
# the fields included in the tsvector. Use concurrent index creation
|
||||
# for minimal downtime.
|
||||
#
|
||||
# If you want, I can prepare the migration, model/index changes and a
|
||||
# Django-code example to wire FTS into this view and tune weights.
|
||||
q = request.GET.get('q', '') or request.GET.get('case-search-input', '')
|
||||
q = q.strip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user