From da165b1aabdd1201e203d7604ccb9a459d6d6f5a Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 28 Apr 2025 14:32:13 +0530 Subject: [PATCH] [UPDT] HELPDESK: Updated faq search method and removed haystack search --- helpdesk/filter.py | 18 ++ helpdesk/models.py | 21 -- helpdesk/search_indexes.py | 12 -- .../helpdesk/faq/faq_category_list.html | 135 +++++++++---- .../helpdesk/faq/faq_category_nav.html | 7 +- helpdesk/templates/helpdesk/faq/faq_list.html | 18 +- .../templates/helpdesk/faq/faq_list_view.html | 134 ++++--------- helpdesk/templates/helpdesk/faq/faq_view.html | 185 +++++------------- .../search/indexes/helpdesk/faq_text.txt | 2 - helpdesk/views.py | 26 ++- horilla/__init__.py | 1 - horilla/haystack_configuration.py | 24 --- 12 files changed, 230 insertions(+), 353 deletions(-) delete mode 100644 helpdesk/search_indexes.py delete mode 100644 helpdesk/templates/search/indexes/helpdesk/faq_text.txt delete mode 100644 horilla/haystack_configuration.py 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' %}
{% for category in faq_categories %} -
-
-

{{category.title}}

- {% if perms.helpdesk.change_faqcategory or perms.helpdesk.delete_faqcategory %} -
- +
+
+

{{category.title}}

+ {% if perms.helpdesk.change_faqcategory or perms.helpdesk.delete_faqcategory %} +
+ -
-
    - {% if perms.helpdesk.change_faqcategory %} -
  • - {% trans "Edit" %} -
  • - {% endif %} - {% if perms.helpdesk.delete_faqcategory %} -
  • -
    - {% csrf_token %} - -
    -
  • - {% endif %} -
-
-
- {% endif %} +
+
    + {% if perms.helpdesk.change_faqcategory %} +
  • + {% trans "Edit" %} +
  • + {% endif %} + {% if perms.helpdesk.delete_faqcategory %} +
  • +
    + {% csrf_token %} + +
    +
  • + {% endif %} +
+
- -

{{category.description}}

- {% trans "View FAQs" %} + {% endif %}
+ +

{{category.description}}

+ {% trans "View FAQs" %} +
+ {% empty %} +
+
+ +

+ {% trans "There are no FAQs at the moment." %} +

+
+
{% endfor %}
diff --git a/helpdesk/templates/helpdesk/faq/faq_category_nav.html b/helpdesk/templates/helpdesk/faq/faq_category_nav.html index 5ce77b8eb..b3d82ff31 100644 --- a/helpdesk/templates/helpdesk/faq/faq_category_nav.html +++ b/helpdesk/templates/helpdesk/faq/faq_category_nav.html @@ -2,7 +2,7 @@

- {{model.get_verbose_name_plural}} + {% trans "FAQ Categories" %}

-
{% comment %}