Skip to content

Commit

Permalink
feat(HelpdeskSearch): Use additional stopwords from doctype
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurali27 committed Sep 12, 2024
1 parent 4ba371d commit 88ffc70
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
Empty file.
8 changes: 8 additions & 0 deletions helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.js
Original file line number Diff line number Diff line change
@@ -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) {

// },
// });
56 changes: 56 additions & 0 deletions helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.json
Original file line number Diff line number Diff line change
@@ -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": []
}
9 changes: 9 additions & 0 deletions helpdesk/helpdesk/doctype/hd_stopword/hd_stopword.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions helpdesk/helpdesk/doctype/hd_stopword/test_hd_stopword.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions helpdesk/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"[\[\]{}<>+!-]")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 = {}
Expand Down

0 comments on commit 88ffc70

Please sign in to comment.