fragments with motifs in search results
authorJan Szejko <janek37@gmail.com>
Thu, 14 Dec 2017 16:44:37 +0000 (17:44 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 14 Dec 2017 16:44:37 +0000 (17:44 +0100)
src/catalogue/templates/catalogue/book_searched.html
src/search/index.py
src/search/templatetags/search_tags.py

index 4e91432..e257467 100644 (file)
               {% inline_tag_list hit.themes_hit  %}
             {% endif %}
             <a href="{{hit.fragment.get_absolute_url}}">
-              {{hit.snippet|safe}}
+              {% if hit.snippet %}
+                {{hit.snippet|safe}}
+              {% else %}
+                {{hit.fragment.text|truncatewords_html:15|safe}}
+              {% endif %}
             </a>
           </div>
         {% endif %}
index ce60978..70214c5 100644 (file)
@@ -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):
         """
index ea8d4ed..f03aa67 100644 (file)
@@ -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))