Verified Commit 70762b56 authored by Thibaut Broggi's avatar Thibaut Broggi
Browse files

Improve search

	Search now look for keywords in both the title and the content
	of the article. It is now case-insensitive.
parent c4f1cf88
Pipeline #1197 passed with stages
in 1 minute and 57 seconds
......@@ -5,6 +5,7 @@ from django.views.generic.edit import UpdateView
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse, reverse_lazy
from django.db.models import Count
from django.db.models import Q
from django import forms
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
......@@ -34,8 +35,10 @@ class ArticleList(ListView):
else:
qs = Article.objects.filter()
if self.request.GET.get('q', '') != '':
qs = qs.filter(title__contains=self.request.GET.get('q', ''))
search_keywords = self.request.GET.get('q', '')
if search_keywords != '':
qs = qs.filter(Q(title__icontains=search_keywords)
| Q(extracts__icontains=search_keywords))
filter_tag = self.kwargs.get("filter_tag", self.filter_tag)
if filter_tag is not None:
......@@ -49,7 +52,6 @@ class ArticleList(ListView):
qs = Tag.objects.annotate(num_times=Count('taggit_taggeditem_items')).all()
qs = qs.order_by('-num_times')
context["tags"] = qs
context["search"] = self.request.GET.get("q", '')
return context
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment