Skip to content

Commit

Permalink
Merge pull request #249 from abaisero/feature/improved_search
Browse files Browse the repository at this point in the history
fix: generalizes player search query format
  • Loading branch information
amj authored Apr 29, 2022
2 parents 87fceca + 78d404e commit b70a668
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions agagd/agagd_core/views/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import functools
import operator

from agagd_core.models import Member
from agagd_core.tables.search import SearchResultsTable
from django.db.models import F, Q
Expand All @@ -13,7 +16,7 @@ class SearchView(DetailView):
search_results_template_name = "search_results.html"

def get(self, request):
query = request.GET.get("q", "")
query = request.GET.get("q", "").strip()

if not query:
return TemplateResponse(request, self.template_name)
Expand All @@ -22,9 +25,14 @@ def get(self, request):
member_id = [int(query)]
return HttpResponseRedirect(reverse("players_profile", args=member_id))

# constructing intersection queryset from query tokens
tokens = query.split()
querysets = (Q(full_name__icontains=token) for token in tokens)
queryset = functools.reduce(operator.and_, querysets)

member_table_data = (
Member.objects.filter(Q(member_id=F("players__pin_player")))
.filter(full_name__icontains=query)
.filter(queryset)
.values(
"member_id",
"chapter_id",
Expand Down

0 comments on commit b70a668

Please sign in to comment.