fix findable
[wolnelektury.git] / src / search / forms.py
index f3bf0c0..edbc9d3 100644 (file)
@@ -3,7 +3,7 @@
 #
 from django.apps import apps
 from django.conf import settings
 #
 from django.apps import apps
 from django.conf import settings
-from django.contrib.postgres.search import SearchHeadline, SearchRank, SearchQuery
+from django.contrib.postgres.search import SearchHeadline, SearchQuery
 from django import forms
 from django.utils.translation import gettext_lazy as _
 from catalogue.constants import LANGUAGES_3TO2
 from django import forms
 from django.utils.translation import gettext_lazy as _
 from catalogue.constants import LANGUAGES_3TO2
@@ -85,9 +85,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(),
             '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(),
             '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
         }
             'art': picture.models.Picture.objects.all(),
             # art pieces
         }
@@ -165,9 +165,7 @@ class SearchFilters(forms.Form):
         ).filter(search_vector=squery)
         books = books.exclude(ancestor__in=books)
 
         ).filter(search_vector=squery)
         books = books.exclude(ancestor__in=books)
 
-        snippets = qs['snippet'].annotate(
-                    rank=SearchRank('search_vector', squery)
-                ).filter(rank__gt=0).order_by('-rank').annotate(
+        snippets = qs['snippet'].filter(search_vector=squery).annotate(
                     headline=SearchHeadline(
                         'text',
                         query,
                     headline=SearchHeadline(
                         'text',
                         query,