diff --git a/app/app/views.py b/app/app/views.py index f2ebf8eb..23ae92fb 100644 --- a/app/app/views.py +++ b/app/app/views.py @@ -229,13 +229,10 @@ def institutions(request): def search(request): - # f = DocumentFileFilter(request.GET, queryset=DocumentFile.objects.all().defer("document_data")) f = DocumentFileFilter(request.GET, queryset=DocumentFile.objects.all()) template = "app/search.html" - # print(f.qs) - paginator = Paginator(f.qs, 5) # 5 documents per page print(paginator) @@ -243,13 +240,10 @@ def search(request): page_number = request.GET.get("page") try: - # Get the page page_obj = paginator.page(page_number) except PageNotAnInteger: - # If page is not an integer, deliver first page page_obj = paginator.page(1) except EmptyPage: - # If page is out of range (e.g., 9999), deliver last page of results page_obj = paginator.page(paginator.num_pages) print(page_obj) diff --git a/app/general/filters.py b/app/general/filters.py index 70d53310..9f1fbe88 100644 --- a/app/general/filters.py +++ b/app/general/filters.py @@ -9,6 +9,7 @@ class DocumentFileFilter(django_filters.FilterSet): search = django_filters.CharFilter(method="filter_search", label="Search") + institution = ModelMultipleChoiceFilter( queryset=Institution.objects.all(), widget=forms.CheckboxSelectMultiple ) @@ -35,10 +36,11 @@ def filter_search(self, queryset, name, value): if value: queue = SearchQuery(value) search_rank = SearchRank(F("search_vector"), queue) - + search_headline = SearchHeadline("document_data", queue) queryset = ( queryset.annotate( rank=search_rank, + search_headline=search_headline, ) .defer("document_data") .select_related("institution") diff --git a/app/general/forms.py b/app/general/forms.py deleted file mode 100644 index 72c61c73..00000000 --- a/app/general/forms.py +++ /dev/null @@ -1,39 +0,0 @@ -# forms.py -import django_filters -from django import forms - -from general.models import DocumentFile - - -class DocumentFileSearchForm(forms.Form): - title = django_filters.CharFilter(lookup_expr="iexact") - # title = django_filters.CharFilter(lookup_expr='iexact') - - class Meta: - model = DocumentFile - fields = ["subjects", "languages"] - - -# class DocumentFileSearchForm(forms.Form): -# query = forms.CharField(label='Search', max_length=255, required=False) -# -# subjects = forms.MultipleChoiceField( -# choices=[], -# required=False, -# widget=forms.SelectMultiple -# ) -# -# languages = forms.MultipleChoiceField( -# choices=[], -# required=False, -# # widget=forms.CheckboxSelectMultiple -# widget=forms.SelectMultiple -# ) -# -# def __init__(self, *args, **kwargs): -# super().__init__(*args, **kwargs) -# -# self.fields['subjects'].choices = [(cat, cat) for cat in -# Subject.objects.values_list('name', flat=True).distinct()] -# self.fields['languages'].choices = [(brand, brand) for brand in -# Language.objects.values_list('name', flat=True).distinct()] diff --git a/app/templates/app/search.html b/app/templates/app/search.html index c2735cd6..1cb78d24 100644 --- a/app/templates/app/search.html +++ b/app/templates/app/search.html @@ -45,6 +45,10 @@
{% trans "Search a term" %}
{% trans "License:" %} {{ document.license }} +
  • + {% trans "License:" %} + {{ document.document_type }} +
  • {% trans "Mime Type:" %} {{ document.mime_type }}