X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5074895f7d96cbd5fda6a4d566ddb25533137fd4..33f38948f6f42804f6baf7e431bb9a143daf0884:/src/search/views.py?ds=sidebyside diff --git a/src/search/views.py b/src/search/views.py index 70a216e3b..8542e512f 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -17,6 +17,8 @@ from suggest.forms import PublishingSuggestForm import re import json +from wolnelektury.utils import re_escape + def match_word_re(word): if 'sqlite' in settings.DATABASES['default']['ENGINE']: @@ -29,7 +31,7 @@ query_syntax_chars = re.compile(r"[\\/*:(){}]") def remove_query_syntax_chars(query, replace=' '): - return query_syntax_chars.sub(' ', query) + return query_syntax_chars.sub(replace, query) def did_you_mean(query, tokens): @@ -64,15 +66,15 @@ def hint(request): if len(prefix) < 2: return JsonResponse([], safe=False) - prefix = remove_query_syntax_chars(prefix) + prefix = re_escape(' '.join(remove_query_syntax_chars(prefix).split())) try: limit = int(request.GET.get('max', '')) except ValueError: - limit = -1 + limit = 20 else: if limit < 1: - limit = -1 + limit = 20 data = [ { @@ -81,7 +83,7 @@ def hint(request): 'id': author.id, 'url': author.get_absolute_url(), } - for author in Tag.objects.filter(category='author', name__iregex='\m' + prefix)[:10] + for author in Tag.objects.filter(category='author', name__iregex=u'\m' + prefix)[:limit] ] if len(data) < limit: data += [