From 7bdd822d952e629231522af6062e10d7c1f31872 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Thu, 14 Dec 2017 17:44:37 +0100 Subject: [PATCH 1/1] fragments with motifs in search results --- src/catalogue/templates/catalogue/book_searched.html | 6 +++++- src/search/index.py | 2 +- src/search/templatetags/search_tags.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/catalogue/templates/catalogue/book_searched.html b/src/catalogue/templates/catalogue/book_searched.html index 4e914328c..e257467e3 100644 --- a/src/catalogue/templates/catalogue/book_searched.html +++ b/src/catalogue/templates/catalogue/book_searched.html @@ -15,7 +15,11 @@ {% inline_tag_list hit.themes_hit %} {% endif %} - {{hit.snippet|safe}} + {% if hit.snippet %} + {{hit.snippet|safe}} + {% else %} + {{hit.fragment.text|truncatewords_html:15|safe}} + {% endif %} {% endif %} diff --git a/src/search/index.py b/src/search/index.py index ce60978d5..70214c554 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -744,7 +744,7 @@ class Search(SolrIndex): else: query = self.index.query() query = self.apply_filters(query, filters).field_limit(score=True, all_fields=True) - return [SearchResult(found, how_found='search_words') for found in query.execute()] + return [SearchResult(found, how_found='search_words', query_terms=words) for found in query.execute()] def get_snippets(self, searchresult, query, field='text', num=1): """ diff --git a/src/search/templatetags/search_tags.py b/src/search/templatetags/search_tags.py index ea8d4ed0a..f03aa6762 100644 --- a/src/search/templatetags/search_tags.py +++ b/src/search/templatetags/search_tags.py @@ -25,7 +25,7 @@ def book_searched(context, result): # We don't need hits which lead to sections but do not have # snippets. hits = filter(lambda (idx, h): - result.snippets[idx] is not None, + result.snippets[idx] is not None or 'fragment' in h, enumerate(result.hits)) # print "[tmpl: from %d hits selected %d]" % (len(result.hits), len(hits)) -- 2.20.1