diff --git a/app/general/filters.py b/app/general/filters.py index 90fb1b95..12f670a4 100644 --- a/app/general/filters.py +++ b/app/general/filters.py @@ -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. @@ -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, @@ -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) diff --git a/app/templates/app/search.html b/app/templates/app/search.html index f5ee4b62..910fa73f 100644 --- a/app/templates/app/search.html +++ b/app/templates/app/search.html @@ -20,12 +20,18 @@
{% trans "Search a term" %}
{% for result in search_results %}
-

{{ result.heading }}

+

{{ result.heading }}

{{ result.description | truncatewords:10 }}

{% trans "Excerpt:" %} {{ result.search_headline|safe }}

+

+ {% if result.logo_url %} + + {% endif %} +

{{ result.rank }}