X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b2d342589a7889a3b096e7192453d53bd28eed7d..fd753649825bfdefb749506d81ae776e55a5c63c:/src/search/views.py?ds=inline diff --git a/src/search/views.py b/src/search/views.py index c6759ea76..14da6f60d 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -115,7 +115,7 @@ def hint(request): break limit -= 1 data.append({ - 'label': b.title, + 'label': '%s, %s' % (b.title, b.author_unicode()), 'category': _('book'), 'id': b.id, 'url': b.get_absolute_url() @@ -132,11 +132,18 @@ def hint(request): @cache.never_cache def main(request): query = request.GET.get('q', '') + query = ' '.join(query.split()) + # filter out private use characters + import unicodedata + query = ''.join(ch for ch in query if unicodedata.category(ch) != 'Co') if len(query) < 2: return render_to_response( 'catalogue/search_too_short.html', {'prefix': query}, context_instance=RequestContext(request)) + elif len(query) > 256: + return render_to_response( + 'catalogue/search_too_long.html', {'prefix': query}, context_instance=RequestContext(request)) query = remove_query_syntax_chars(query) @@ -215,7 +222,6 @@ def main(request): text_phrase = filter(ensure_exists, text_phrase) everywhere = filter(ensure_exists, everywhere) - results = author_results + translator_results + title_results + text_phrase + everywhere # ensure books do exists & sort them for res in (author_results, translator_results, title_results, text_phrase, everywhere): res.sort(reverse=True) @@ -228,7 +234,7 @@ def main(request): # #frag = Fragment.objects.get(anchor=anchor) # return HttpResponseRedirect(fragment_hits[0]['fragment'].get_absolute_url()) # return HttpResponseRedirect(results[0].book.get_absolute_url()) - if len(results) == 0: + if not (author_results or translator_results or title_results or text_phrase or everywhere): form = PublishingSuggestForm(initial={"books": query + ", "}) return render_to_response( 'catalogue/search_no_hits.html',