Skip to content

Commit

Permalink
+logo_url in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent authored and friedelwolff committed Jul 25, 2024
1 parent 5bdc4ee commit 3d9c74a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/general/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ def filter_queryset(self, queryset):

# A fixed list of identical fields are required to join queries of
# different classes with `.union()`:
fields = ("id", "heading", "description", "rank", "search_headline", "view")
fields = (
"id",
"heading",
"description",
"rank",
"search_headline",
"view",
"logo_url",
)

# In the queries below, any differences between models must be fixed
# through e.g. `Value` or `F` annotations.
Expand All @@ -59,6 +67,7 @@ def filter_queryset(self, queryset):
Project.objects.annotate(
heading=F("name"),
view=Value("project_detail"),
logo_url=F("logo"),
search_headline=SearchHeadline("description", query, max_words=15, min_words=10),
rank=SearchRank(project_search_vector, query, normalization=16),
search=project_search_vector,
Expand All @@ -76,6 +85,7 @@ def filter_queryset(self, queryset):
queryset = queryset.annotate(
heading=F("title"),
view=Value("document_detail"),
logo_url=Value(""),
rank=search_rank,
search_headline=search_headline,
).values(*fields)
Expand Down
8 changes: 7 additions & 1 deletion app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ <h5 class="card-title">{% trans "Search a term" %}</h5>
<div class="container">
{% for result in search_results %}
<div>
<h3><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<h2><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<p>{{ result.description | truncatewords:10 }}</p>
<p>
<span class="mr-5"><b>{% trans "Excerpt:" %}</b></span>
<span>{{ result.search_headline|safe }}</span>
</p>
<p>
{% if result.logo_url %}
<img src="/media/{{ result.logo_url }}" alt="{{ result.name }} logo"
class="project-logo">
{% endif %}
</p>
<p>
<span><i>{{ result.rank }}</i></span>
</p>
Expand Down

0 comments on commit 3d9c74a

Please sign in to comment.