Skip to content

Commit

Permalink
updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 11, 2024
1 parent 3b326e5 commit 1046909
Showing 1 changed file with 0 additions and 42 deletions.
42 changes: 0 additions & 42 deletions app/app/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os

from django.contrib.postgres.search import SearchHeadline, SearchQuery, SearchRank
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import Count
from django.http import HttpResponse
Expand Down Expand Up @@ -230,45 +227,6 @@ def institutions(request):
return render(request, template_name=template, context=context)


def search(request):
q = request.GET.get("q")

if q:
queue = SearchQuery(q)
search_headline = SearchHeadline("document_data", queue)

documents = (
DocumentFile.objects.annotate(rank=SearchRank("search_vector", queue))
.annotate(search_headline=search_headline)
.filter(search_vector=queue)
.order_by("-rank")
)

else:
documents = None

# Create a Paginator instance with the documents and the number of items per page
paginator = Paginator(documents, 10) if documents else None # Show 10 documents per page

# Get the page number from the request's GET parameters
page_number = request.GET.get("page")

# Use the get_page method to get the Page object for that page number
page_obj = paginator.get_page(page_number) if paginator else None

feature_flag = os.getenv("FEATURE_FLAG", False)

template = "app/search.html"
context = {
"documents": page_obj,
"current_page": "search",
"document_count": len(documents) if documents else 0,
"feature_flag": feature_flag,
}

return render(request, template_name=template, context=context)


def search(request):
page_number = request.GET.get("page", "1")
if not page_number.isdigit():
Expand Down

0 comments on commit 1046909

Please sign in to comment.