- return render_to_response('newsearch/search.html', {'results': results,
- 'did_you_mean': (query is not None) and
- did_you_mean(query, srch.get_tokens(query, field='SIMPLE')),
- 'fuzzy': fuzzy},
- context_instance=RequestContext(request))
+ if len(results) == 1:
+ 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])
+ return HttpResponseRedirect(frag.get_absolute_url())
+ elif len(results) == 0:
+ form = PublishingSuggestForm(initial={"books": query + ", "})
+ return render_to_response('catalogue/search_no_hits.html',
+ {'tags': tag_list, 'prefix': query, "pubsuggest_form": form,
+ 'form': forms.SearchForm()},
+ context_instance=RequestContext(request))
+
+ return render_to_response('catalogue/search_multiple_hits.html',
+ {'tags': tag_list, 'prefix': query,
+ 'results': results, 'from': forms.SearchForm()},
+ context_instance=RequestContext(request))
+
+ # return render_to_response('newsearch/search.html', {'results': results,
+ # 'did_you_mean': (query is not None) and
+ # did_you_mean(query, srch.get_tokens(query, field='SIMPLE')),
+ # 'fuzzy': fuzzy},
+ # context_instance=RequestContext(request))