diff --git a/helpdesk/filter.py b/helpdesk/filter.py index 32376a721..ae15cd1ac 100644 --- a/helpdesk/filter.py +++ b/helpdesk/filter.py @@ -109,3 +109,21 @@ class TicketReGroup: ("assigned_to", "Assigner"), ("employee_id__employee_work_info__company_id", "Company"), ] + + +class FaqSearch(FilterSet): + search = CharFilter(method="search_method", lookup_expr="icontains") + + class Meta: + model = FAQ + fields = ["search"] + + def search_method(self, queryset, _, value): + """ + This method is used to add custom search condition + """ + return ( + queryset.filter(question__icontains=value) + | queryset.filter(answer__icontains=value) + | queryset.filter(tags__title__icontains=value) + ).distinct() diff --git a/helpdesk/models.py b/helpdesk/models.py index 567fc02fb..4d7883da1 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -275,24 +275,3 @@ class FAQ(HorillaModel): class Meta: verbose_name = _("FAQ") verbose_name_plural = _("FAQs") - - -# updating the faq search index when a new faq is created or deleted - - -def update_index(sender, instance, **kwargs): - from .search_indexes import FAQIndex - - index = FAQIndex() - index.update_object(instance) - - -def remove_from_index(sender, instance, **kwargs): - from .search_indexes import FAQIndex - - index = FAQIndex() - index.remove_object(instance) - - -post_save.connect(update_index, sender=FAQ) -post_delete.connect(remove_from_index, sender=FAQ) diff --git a/helpdesk/search_indexes.py b/helpdesk/search_indexes.py deleted file mode 100644 index 2e1b80b46..000000000 --- a/helpdesk/search_indexes.py +++ /dev/null @@ -1,12 +0,0 @@ -from haystack import indexes - -from .models import FAQ - - -class FAQIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True) - question = indexes.CharField(model_attr="question") - answer = indexes.CharField(model_attr="answer") - - def get_model(self): - return FAQ diff --git a/helpdesk/templates/helpdesk/faq/faq_category_list.html b/helpdesk/templates/helpdesk/faq/faq_category_list.html index 72a5d4309..d97647ca6 100644 --- a/helpdesk/templates/helpdesk/faq/faq_category_list.html +++ b/helpdesk/templates/helpdesk/faq/faq_category_list.html @@ -1,49 +1,102 @@ -{% load i18n %} - +{% load i18n static %} {% include 'filter_tags.html' %}
{{category.description}}
- {% trans "View FAQs" %} + {% endif %}{{category.description}}
+ {% trans "View FAQs" %} +
+