X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3c0d04a3693fb70566f5ba7b045a24c0d5e955b1..94a4fcc7ab9e1713dc2defc8b35c875fc90f6fa5:/src/search/forms.py?ds=sidebyside diff --git a/src/search/forms.py b/src/search/forms.py index 1e680fa4f..dee9c7774 100644 --- a/src/search/forms.py +++ b/src/search/forms.py @@ -10,24 +10,10 @@ from catalogue.constants import LANGUAGES_3TO2 import catalogue.models import pdcounter.models import picture.models -from .fields import JQueryAutoCompleteSearchField, InlineRadioWidget +from .fields import InlineRadioWidget from .utils import UnaccentSearchQuery, UnaccentSearchVector -class SearchForm(forms.Form): - q = JQueryAutoCompleteSearchField(label=_('Search')) - # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"}) - - def __init__(self, source, *args, **kwargs): - kwargs['auto_id'] = False - super(SearchForm, self).__init__(*args, **kwargs) - self.fields['q'].widget.attrs['id'] = 'search' - self.fields['q'].widget.attrs['autocomplete'] = 'off' - self.fields['q'].widget.attrs['data-source'] = source - if 'q' not in self.data: - self.fields['q'].widget.attrs['placeholder'] = _('title, author, epoch, kind, genre, phrase') - - class SearchFilters(forms.Form): q = forms.CharField( required=False, widget=forms.HiddenInput(), @@ -85,9 +71,9 @@ class SearchFilters(forms.Form): 'theme': catalogue.models.Tag.objects.filter(category='theme'), 'genre': catalogue.models.Tag.objects.filter(category='genre'), 'collection': catalogue.models.Collection.objects.all(), - 'book': catalogue.models.Book.objects.all(), #findable + 'book': catalogue.models.Book.objects.filter(findable=True), 'pdbook': pdcounter.models.BookStub.objects.all(), - 'snippet': catalogue.models.Snippet.objects.all(), + 'snippet': catalogue.models.Snippet.objects.filter(book__findable=True), 'art': picture.models.Picture.objects.all(), # art pieces } @@ -104,14 +90,14 @@ class SearchFilters(forms.Form): qs['pdbook'] = qs['pdbook'].none() if c != 'quote': qs['snippet'] = qs['snippet'].none() if c != 'art': qs['art'] = qs['art'].none() - qs['art'] = Picture.objects.none() + qs['art'] = picture.models.Picture.objects.none() if self.cleaned_data['format']: c = self.cleaned_data['format'] qs['author'] = qs['author'].none() qs['pdauthor'] = qs['pdauthor'].none() qs['theme'] = qs['theme'].none() - qs['genre'] = qs['genrer'].none() + qs['genre'] = qs['genre'].none() qs['collection'] = qs['collection'].none() if c == 'art': qs['book'] = qs['book'].none() @@ -158,23 +144,22 @@ class SearchFilters(forms.Form): def results(self): qs = self.get_querysets() query = self.cleaned_data['q'] - squery = UnaccentSearchQuery(query, config='polish') - query = SearchQuery(query, config='polish') + squery = UnaccentSearchQuery(query, config=settings.SEARCH_CONFIG) + query = SearchQuery(query, config=settings.SEARCH_CONFIG) books = qs['book'].annotate( search_vector=UnaccentSearchVector('title') ).filter(search_vector=squery) - books = books.exclude(ancestor__in=books) + books = books.exclude(ancestor__in=books).order_by('-popularity__count') snippets = qs['snippet'].filter(search_vector=squery).annotate( headline=SearchHeadline( 'text', query, - config='polish', + config=settings.SEARCH_CONFIG, start_sel='', stop_sel='', - highlight_all=True ) - )[:100] + ).order_by('-book__popularity__count', 'sec')[:100] snippets_by_book = {} for snippet in snippets: snippet_list = snippets_by_book.setdefault(snippet.book, [])