X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/bda5443f87666bebd8594f6c2586677e218ae18b..6592ad610dc42a6242b5d5446addfb7a1feb01e0:/src/search/views.py?ds=inline diff --git a/src/search/views.py b/src/search/views.py index 9be6732bb..2fe94f431 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings from django.http.response import HttpResponseRedirect -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.views.decorators import cache from django.http import HttpResponse, JsonResponse @@ -27,7 +25,7 @@ def match_word_re(word): return "[[:<:]]%s[[:>:]]" % word -query_syntax_chars = re.compile(r"[\\/*:(){}?.]") +query_syntax_chars = re.compile(r"[\\/*:(){}?.[\]+]") def remove_query_syntax_chars(query, replace=' '): @@ -108,42 +106,42 @@ def hint(request): def main(request): query = request.GET.get('q', '') if len(query) < 2: - return render_to_response( - 'catalogue/search_too_short.html', {'prefix': query}, - context_instance=RequestContext(request)) + return render( + request, 'catalogue/search_too_short.html', + {'prefix': query}) elif len(query) > 256: - return render_to_response( - 'catalogue/search_too_long.html', {'prefix': query}, context_instance=RequestContext(request)) + return render( + request, 'catalogue/search_too_long.html', + {'prefix': query}) query = prepare_query(query) pd_authors = search_pd_authors(query) books = search_books(query) pictures = search_pictures(query) - suggestion = u'' + suggestion = '' if not (books or pictures or pd_authors): form = PublishingSuggestForm(initial={"books": query + ", "}) - return render_to_response( + return render( + request, 'catalogue/search_no_hits.html', { 'form': form, 'did_you_mean': suggestion - }, - context_instance=RequestContext(request)) + }) if not (books or pictures) and len(pd_authors) == 1: return HttpResponseRedirect(pd_authors[0].get_absolute_url()) - return render_to_response( + return render( + request, 'catalogue/search_multiple_hits.html', { 'pd_authors': pd_authors, 'books': books, 'pictures': pictures, 'did_you_mean': suggestion - }, - context_instance=RequestContext(request)) - + }) def search_books(query): search = Search() @@ -151,10 +149,10 @@ def search_books(query): search_fields = [] words = query.split() fieldsets = ( - (['authors'], True), - (['title'], True), - (['metadata'], True), - (['text', 'themes_pl'], False), + (['authors', 'authors_nonstem'], True), + (['title', 'title_nonstem'], True), + (['metadata', 'metadata_nonstem'], True), + (['text', 'text_nonstem', 'themes_pl', 'themes_pl_nonstem'], False), ) for fields, is_book in fieldsets: search_fields += fields @@ -191,10 +189,10 @@ def search_pictures(query): search_fields = [] words = query.split() fieldsets = ( - (['authors'], True), - (['title'], True), - (['metadata'], True), - (['themes_pl'], False), + (['authors', 'authors_nonstem'], True), + (['title', 'title_nonstem'], True), + (['metadata', 'metadata_nonstem'], True), + (['themes_pl', 'themes_pl_nonstem'], False), ) for fields, is_book in fieldsets: search_fields += fields