- 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))
+ results.sort(reverse=True)
+
+ for r in results:
+ print "-----"
+ for h in r.hits:
+ print "- %s" % h
+
+ # Did you mean?
+ suggestion = did_you_mean(query, srch.get_tokens(toks, field="SIMPLE"))
+
+ 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,
+ "form": form,
+ 'did_you_mean': suggestion},
+ context_instance=RequestContext(request))
+
+ return render_to_response('catalogue/search_multiple_hits.html',
+ {'tags': tag_list,
+ 'prefix': query,
+ 'results': results,
+ 'did_you_mean': suggestion},
+ context_instance=RequestContext(request))