- if len(results[0].hits) == 0:
- return HttpResponseRedirect(results[0].book.get_absolute_url())
- elif len(results[0].hits) == 1 and results[0].hits[0] is not None:
- frag = Fragment.objects.get(anchor=results[0].hits[0])
+ fragment_hits = filter(lambda h: 'fragment' in h, results[0].hits)
+ if len(fragment_hits) == 1:
+ anchor = fragment_hits[0]['fragment']
+ frag = Fragment.objects.get(anchor=anchor)