From: Radek Czajka Date: Fri, 20 Jan 2012 14:24:19 +0000 (+0100) Subject: search fixes X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/bcd038fcea6b45b29ff3831b31f758dcec6b4157?ds=inline search fixes --- diff --git a/apps/search/index.py b/apps/search/index.py index df44888df..9972c2c56 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -653,7 +653,11 @@ class SearchResult(object): hits = sections.values() for f in frags: - frag = catalogue.models.Fragment.objects.get(anchor=f[FRAGMENT]) + try: + frag = catalogue.models.Fragment.objects.get(anchor=f[FRAGMENT]) + except catalogue.models.Fragment.DoesNotExist: + # stale index + continue # Figure out if we were searching for a token matching some word in theme name. themes = frag.tags.filter(category='theme') diff --git a/apps/search/templatetags/search_tags.py b/apps/search/templatetags/search_tags.py index 8ae648d1d..32d5b64c5 100644 --- a/apps/search/templatetags/search_tags.py +++ b/apps/search/templatetags/search_tags.py @@ -25,7 +25,6 @@ register = template.Library() @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(context, book) # snippets = [] # for hit in result.hits: @@ -36,10 +35,15 @@ def book_searched(context, 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) - for hit in vals['hits']: + for hit in hits: hit['snippets'] = map(lambda s: s.replace("\n", "
").replace('---', '—'), hit['snippets']) - return vals + return { + 'related': book.related_info(), + 'book': book, + 'request': context.get('request'), + 'hits': hits, + } diff --git a/wolnelektury/templates/catalogue/search_multiple_hits.html b/wolnelektury/templates/catalogue/search_multiple_hits.html index 0a7dc1cf1..31e67a8c1 100644 --- a/wolnelektury/templates/catalogue/search_multiple_hits.html +++ b/wolnelektury/templates/catalogue/search_multiple_hits.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load search_tags pagination_tags %} +{% load catalogue_tags search_tags pagination_tags %} {% block titleextra %}{% trans "Search" %}{% endblock %} @@ -23,7 +23,7 @@
    {% for author in results.author %}
  1. - {{author.book.short_html}} + {% book_short author.book %}
  2. {% endfor %}
@@ -40,7 +40,7 @@
    {% for result in results.title %}
  1. - {{result.book.short_html}} + {% book_short result.book %}
  2. {% endfor %}