Correction résultats recherche avec tags

Fix #203
This commit is contained in:
Jean-Marie Favreau 2024-11-17 23:23:15 +01:00
parent 47aedc706b
commit c3f6d6920e

View File

@ -65,7 +65,7 @@ from django.utils import timezone
from django.utils.html import escape from django.utils.html import escape
from datetime import date, timedelta from datetime import date, timedelta
from django.utils.timezone import datetime from django.utils.timezone import datetime
from django.db.models import Q, Subquery, OuterRef, Count, F from django.db.models import Q, Subquery, OuterRef, Count, F, Func
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -926,8 +926,12 @@ def event_search(request, full=False):
) )
if 'q' in request.GET: if 'q' in request.GET:
categories = Category.objects.filter(name__icontains=request.GET['q']) categories = Category.objects.filter(name__icontains=request.GET['q'])
tags = list(set([item for row in Event.objects.extra(where=['%s ILIKE ANY (tags)'], params=[request.GET['q']]).values_list('tags', flat=True).distinct() for item in row])) s_q = remove_accents(request.GET['q'].lower())
tags.sort(key=lambda x: remove_accents(x).lower()) tags = Event.objects.extra(where=['%s ILIKE ANY (tags)'], params=[request.GET['q']]).annotate(arr_tags=Func(F('tags'), function='unnest')).values_list('arr_tags', flat=True).distinct()
tags = [(t, remove_accents(t).lower()) for t in tags]
tags = [t for t in tags if s_q == t[1]]
tags.sort(key=lambda x: x[1])
tags = [t[0] for t in tags]
places = Place.objects.filter(Q(name__icontains=request.GET['q'])) places = Place.objects.filter(Q(name__icontains=request.GET['q']))
paginator = PaginatorFilter(filter, 10, request) paginator = PaginatorFilter(filter, 10, request)