Skip to content

Commit

Permalink
Merge pull request #1987 from frappe/develop
Browse files Browse the repository at this point in the history
chore(release): dev to main
  • Loading branch information
balamurali27 committed Sep 17, 2024
2 parents 39faab9 + 6c31c16 commit 34c4b11
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 20 deletions.
3 changes: 2 additions & 1 deletion desk/src/components/AssignmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<template #body-content>
<SearchComplete
class="form-control"
value=""
value="1"
search-field="is_active"
doctype="HD Agent"
:reset-input="true"
@change="
Expand Down
11 changes: 11 additions & 0 deletions desk/src/components/EmailBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ const emit = defineEmits(["reply"]);
const { isMobileView } = useScreenSize();
</script>

<style>
.email-content {
max-width: 100%;
}
.email-content > * {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
}
</style>
2 changes: 1 addition & 1 deletion desk/src/components/ticket/TicketAgentActivities.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="h-screen overflow-y-auto py-3.5 comm-area w-full">
<div class="h-screen overflow-y-auto py-3.5 comm-area">
<div v-for="(activity, i) in activities" :key="activity.key">
<div class="flex gap-4 px-3 lg:px-6 w-full">
<div
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/TicketAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</template>
</LayoutHeader>
<div v-if="ticket.data" class="flex h-screen overflow-hidden">
<div class="flex flex-1 flex-col">
<div class="flex flex-1 flex-col w-[calc(100%-382px)]">
<div class="flex items-center justify-between border-b py-1 pr-2.5">
<span class="pl-6 text-lg font-semibold">Activity</span>
<Switch
Expand Down
2 changes: 1 addition & 1 deletion frappe-ui
1 change: 1 addition & 0 deletions helpdesk/api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_noun_phrases(blob: TextBlob):

@frappe.whitelist()
def search(query: str):
query = query.strip().lower()
out = hd_search(query, only_articles=True)
if not out: # fallback
blob = TextBlob(query)
Expand Down
9 changes: 8 additions & 1 deletion helpdesk/helpdesk/doctype/hd_settings/hd_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

frappe.ui.form.on("HD Settings", {
refresh: function (frm) {
//
frm.add_custom_button(__("Regenerate Search Index"), () => {
frappe.call({
method: "helpdesk.search.build_index",
callback: function (r) {
frappe.msgprint(__("Search Index Regenerated"));
},
});
});
},
});
43 changes: 41 additions & 2 deletions helpdesk/helpdesk/doctype/hd_settings/hd_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
"setup_section",
"setup_complete",
"initial_helpdesk_name_setup_skipped",
"column_break_hjfh"
"column_break_hjfh",
"search_tab",
"name_weight",
"subject_weight",
"column_break_qoxt",
"description_weight",
"headings_weight"
],
"fields": [
{
Expand Down Expand Up @@ -235,11 +241,44 @@
{
"fieldname": "column_break_nvbf",
"fieldtype": "Column Break"
},
{
"fieldname": "search_tab",
"fieldtype": "Tab Break",
"label": "Search"
},
{
"default": "1",
"fieldname": "name_weight",
"fieldtype": "Int",
"label": "Name Weight"
},
{
"default": "6",
"fieldname": "subject_weight",
"fieldtype": "Int",
"label": "Subject Weight"
},
{
"default": "5",
"fieldname": "description_weight",
"fieldtype": "Int",
"label": "Description Weight"
},
{
"fieldname": "column_break_qoxt",
"fieldtype": "Column Break"
},
{
"default": "8",
"fieldname": "headings_weight",
"fieldtype": "Int",
"label": "Headings Weight"
}
],
"issingle": 1,
"links": [],
"modified": "2023-08-23 17:59:49.761375",
"modified": "2024-09-18 00:47:04.055942",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Settings",
Expand Down
Empty file.
35 changes: 35 additions & 0 deletions helpdesk/helpdesk/doctype/hd_synonym/hd_synonym.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:synonym",
"creation": "2024-09-16 23:26:46.588705",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"synonym"
],
"fields": [
{
"allow_in_quick_entry": 1,
"fieldname": "synonym",
"fieldtype": "Data",
"in_list_view": 1,
"label": "synonym",
"unique": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-09-16 23:28:52.647865",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Synonym",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions helpdesk/helpdesk/doctype/hd_synonym/hd_synonym.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 HDSynonym(Document):
pass
Empty file.
8 changes: 8 additions & 0 deletions helpdesk/helpdesk/doctype/hd_synonyms/hd_synonyms.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 Synonyms", {
// refresh(frm) {

// },
// });
51 changes: 51 additions & 0 deletions helpdesk/helpdesk/doctype/hd_synonyms/hd_synonyms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:word",
"creation": "2024-09-16 23:26:22.049229",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"word",
"synonyms"
],
"fields": [
{
"fieldname": "synonyms",
"fieldtype": "Table",
"label": "Synonyms",
"options": "HD Synonym"
},
{
"fieldname": "word",
"fieldtype": "Data",
"label": "Word",
"unique": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-16 23:38:22.053418",
"modified_by": "Administrator",
"module": "Helpdesk",
"name": "HD Synonyms",
"naming_rule": "Expression (old style)",
"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_synonyms/hd_synonyms.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 HDSynonyms(Document):
pass
9 changes: 9 additions & 0 deletions helpdesk/helpdesk/doctype/hd_synonyms/test_hd_synonyms.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 TestHDSynonyms(FrappeTestCase):
pass
57 changes: 44 additions & 13 deletions helpdesk/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from contextlib import suppress
from copy import deepcopy
from math import isclose
from typing import TYPE_CHECKING

import frappe
from bs4 import BeautifulSoup, PageElement
Expand All @@ -21,6 +22,9 @@

from helpdesk.utils import is_agent

if TYPE_CHECKING:
from helpdesk.helpdesk.doctype.hd_settings.hd_settings import HDSettings

STOPWORDS = [
"a",
"is",
Expand Down Expand Up @@ -75,6 +79,14 @@ def get_stopwords():
return STOPWORDS + frappe.get_all("HD Stopword", {"enabled": True}, pluck="name")


@redis_cache(1800)
def get_synonym_words() -> list[str]:
ret = frappe.get_all("HD Synonym", ["name"], as_list=True) + frappe.get_all(
"HD Synonyms", ["name"], as_list=True
)
return [r[0] for r in ret]


class Search:
unsafe_chars = re.compile(r"[\[\]{}<>+!-]")

Expand Down Expand Up @@ -107,8 +119,16 @@ def create_index(self):
definition=index_def,
stopwords=get_stopwords(),
)
self.add_synonyms()

self._index_exists = True

def add_synonyms(self):
for word, synonym in frappe.get_all(
"HD Synonym", ["parent", "name"], as_list=True
):
self.redis.ft(self.index_name).synupdate(word, True, word, synonym)

def add_document(self, id, doc):
doc = frappe._dict(doc)
doc_id = self.redis.make_key(f"{self.prefix}:{id}").decode()
Expand Down Expand Up @@ -188,15 +208,6 @@ def index_exists(self):


class HelpdeskSearch(Search):
schema = [
{"name": "name", "weight": 2},
{"name": "subject", "weight": 6},
{"name": "description", "weight": 6},
{"name": "headings", "weight": 8},
{"name": "team", "type": "tag"},
{"name": "modified", "sortable": True},
{"name": "creation", "sortable": True},
]

DOCTYPE_FIELDS = {
"HD Ticket": [
Expand All @@ -219,7 +230,17 @@ class HelpdeskSearch(Search):
}

def __init__(self):
super().__init__("helpdesk_idx", "search_doc", self.schema)
settings: "HDSettings" = frappe.get_cached_doc("HD Settings")
schema = [
{"name": "name", "weight": settings.name_weight or 1},
{"name": "subject", "weight": settings.subject_weight or 6},
{"name": "description", "weight": settings.description_weight or 5},
{"name": "headings", "weight": settings.headings_weight or 8},
{"name": "team", "type": "tag"},
{"name": "modified", "sortable": True},
{"name": "creation", "sortable": True},
]
super().__init__("helpdesk_idx", "search_doc", schema)

def build_index(self):
self.drop_index()
Expand Down Expand Up @@ -325,9 +346,18 @@ def search(query, only_articles=False):
search = HelpdeskSearch()
query = search.clean_query(query)
query_parts = query.split()
query = " ".join(
[f"{q}*" for q in query_parts if q not in get_stopwords()]
) # for stopwords to be ignored
query = ""
for part in query_parts:
if part in get_synonym_words():
query += f" {part}"
continue
if part in get_stopwords():
continue
if len(part) > 3:
query += f" %{part}%"
else:
query += f" {part}*"

result = search.search(query, start=0, highlight=True)
groups = {}
for r in result.docs:
Expand All @@ -347,6 +377,7 @@ def search(query, only_articles=False):
return out


@frappe.whitelist()
@filelock("helpdesk_search_indexing", timeout=60)
def build_index():
frappe.cache().set_value("helpdesk_search_indexing_in_progress", True)
Expand Down

0 comments on commit 34c4b11

Please sign in to comment.