Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 11, 2024
1 parent 5b5877c commit 3b326e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 1 addition & 3 deletions app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ def search(request):

template = "app/search.html"

ordered_queryset = f.qs.order_by("id")

paginator = Paginator(ordered_queryset, 5) # 5 documents per page
paginator = Paginator(f.qs, 5) # 5 documents per page

try:
page_obj = paginator.page(page_number)
Expand Down
33 changes: 19 additions & 14 deletions app/general/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,28 @@ class Meta:
"languages",
]

def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)

search = self.form.cleaned_data.get("search", "")
queue = SearchQuery(search.strip())
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")
).order_by("-rank")

return queryset

def filter_search(self, queryset, name, value):
if value:
queue = SearchQuery(value.strip())
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")
.filter(search_vector=queue)
.order_by("-rank", "id")
)
return queryset
return queryset.filter(search_vector=queue)

else:
return queryset

0 comments on commit 3b326e5

Please sign in to comment.