diff --git a/helpdesk/helpdesk/doctype/hd_stopword/__init__.py b/helpdesk/helpdesk/doctype/hd_stopword/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.js b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.js new file mode 100644 index 000000000..98975ee32 --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.js @@ -0,0 +1,8 @@ +// Copyright (c) 2024, Frappe Technologies and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("HD Stopword", { +// refresh(frm) { + +// }, +// }); diff --git a/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.json b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.json new file mode 100644 index 000000000..b69891e4d --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.json @@ -0,0 +1,56 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:word", + "creation": "2024-09-12 16:08:27.022111", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "word", + "column_break_jyol", + "enabled" + ], + "fields": [ + { + "fieldname": "word", + "fieldtype": "Data", + "label": "Word", + "unique": 1 + }, + { + "default": "1", + "fieldname": "enabled", + "fieldtype": "Check", + "label": "Enabled" + }, + { + "fieldname": "column_break_jyol", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-09-12 16:10:05.577545", + "modified_by": "Administrator", + "module": "Helpdesk", + "name": "HD Stopword", + "naming_rule": "By fieldname", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "creation", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.py b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.py new file mode 100644 index 000000000..9d1b85906 --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, Frappe Technologies and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class HDStopword(Document): + pass diff --git a/helpdesk/helpdesk/doctype/hd_stopword/test_hd_stopword.py b/helpdesk/helpdesk/doctype/hd_stopword/test_hd_stopword.py new file mode 100644 index 000000000..204646acc --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_stopword/test_hd_stopword.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, Frappe Technologies and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestHDStopword(FrappeTestCase): + pass diff --git a/helpdesk/search.py b/helpdesk/search.py index a890515ba..33052425b 100644 --- a/helpdesk/search.py +++ b/helpdesk/search.py @@ -12,6 +12,7 @@ import frappe from bs4 import BeautifulSoup, PageElement from frappe.utils import cstr, strip_html_tags, update_progress_bar +from frappe.utils.caching import redis_cache from frappe.utils.synchronization import filelock from redis.commands.search.field import TagField, TextField from redis.commands.search.indexDefinition import IndexDefinition @@ -65,9 +66,15 @@ "has", "been", "urgent", + "want", ] +@redis_cache(3600 * 24) +def get_stopwords(): + return STOPWORDS + frappe.get_all("HD Stopword", {"enabled": True}, pluck="name") + + class Search: unsafe_chars = re.compile(r"[\[\]{}<>+!-]") @@ -98,7 +105,7 @@ def create_index(self): self.redis.ft(self.index_name).create_index( schema, definition=index_def, - stopwords=STOPWORDS, + stopwords=get_stopwords(), ) self._index_exists = True @@ -316,7 +323,7 @@ def search(query, only_articles=False): query = search.clean_query(query) query_parts = query.split() query = " ".join( - [f"{q}*" for q in query_parts if q not in STOPWORDS] + [f"{q}*" for q in query_parts if q not in get_stopwords()] ) # for stopwords to be ignored result = search.search(query, start=0, highlight=True) groups = {}