- print r.parts
-
- 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))
+ print "-----"
+ for h in r.hits:
+ print "- %s" % h
+
+ 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},
+ context_instance=RequestContext(request))
+
+ return render_to_response('catalogue/search_multiple_hits.html',
+ {'tags': tag_list, 'prefix': query,
+ 'results': results},
+ 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))