search fixes
[wolnelektury.git] / apps / search / templatetags / search_tags.py
index 03e33c8..97deb9d 100644 (file)
@@ -22,10 +22,9 @@ from catalogue.models import Book
 register = template.Library()
 
 
-@register.inclusion_tag('catalogue/book_searched.html')
-def book_searched(result):
+@register.inclusion_tag('catalogue/book_searched.html', takes_context=True)
+def book_searched(context, result):
     book = Book.objects.get(pk=result.book_id)
-    vals = book_wide(book)
 
     # snippets = []
     # for hit in result.hits:
@@ -36,10 +35,18 @@ def book_searched(result):
 
     # We don't need hits which lead to sections but do not have
     # snippets.
-    vals['hits'] = filter(lambda h: 'fragment' in h or
-                          h['snippets'], result.hits)
+    hits = filter(lambda h: 'fragment' in h or
+                  h['snippets'], result.hits)[0:5]
 
-    for hit in vals['hits']:
+    for hit in hits:
         hit['snippets'] = map(lambda s: s.replace("\n", "<br />").replace('---', '&mdash;'), hit['snippets'])
 
-    return vals
+    return {
+        'related': book.related_info(),
+        'book': book,
+        'main_link': book.get_absolute_url(),
+        'request': context.get('request'),
+        'hits': hits,
+        'main_link': book.get_absolute_url(),
+    }
+