Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index kb articles and show in search #1841

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions desk/src/components/command-palette/CP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ import {
ComboboxOptions,
ComboboxOption,
} from "@headlessui/vue";
import CPItem from "./CPItem.vue";
import CPTicket from "./CPTicket.vue";
import CPGroup from "./CPGroup.vue";
import CPGroupResult from "./CPGroupResult.vue";
import LucideLayoutGrid from "~icons/lucide/layout-grid";
import LucideSearch from "~icons/lucide/file-search";
import LucideTicket from "~icons/lucide/ticket";
import LucideUser from "~icons/lucide/user";
import LucideBookOpen from "~icons/lucide/book-open";

let show = ref(false);

Expand All @@ -95,8 +96,8 @@ export default {
ComboboxInput,
ComboboxOptions,
ComboboxOption,
CPTicket,
CPItem,
CPGroup,
CPGroupResult,
},
setup() {
return { show };
Expand All @@ -118,8 +119,9 @@ export default {
transform(groups) {
for (let group of groups) {
if (group.title === "Tickets") {
group.component = "CPTicket";
group.component = "CPGroupResult";
group.items = group.items.map((item) => {
item.showName = true;
item.route = {
name: "TicketAgent",
params: {
Expand All @@ -128,6 +130,18 @@ export default {
};
return item;
});
} else if (group.title === "Articles") {
group.component = "CPGroupResult";
group.items = group.items.map((item) => {
item.subject = item.payload.category + " / " + item.subject;
item.route = {
name: "DeskKBArticle",
params: {
articleId: item.name,
},
};
return item;
});
}
}
return groups;
Expand All @@ -139,17 +153,23 @@ export default {
navigationItems() {
return {
title: "Jump to",
component: "CPItem",
component: "CPGroup",
items: [
{
title: "Tickets",
icon: () => h(LucideTicket),
route: { name: "TicketsAgent" },
},
// {
// title: "Agents",
// icon: () => h(LucideUser),
// route: { name: "AgentList" },
// condition: () => true,
// },
{
title: "Agents",
icon: () => h(LucideUser),
route: { name: "AgentList" },
title: "Knowledge Base",
icon: () => h(LucideBookOpen),
route: { name: "DeskKBHome" },
condition: () => true,
},
].filter((item) => (item.condition ? item.condition() : true)),
Expand All @@ -159,7 +179,7 @@ export default {
return {
title: "Search",
hideTitle: true,
component: "CPItem",
component: "CPGroup",
items: [
{
title: `Search for "${this.query}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
class="mr-3 h-4 w-4 text-gray-700"
/>
<span class="overflow-hidden text-ellipsis whitespace-nowrap">
<span class="text-sm">
#
{{ item.name }}
</span>
&nbsp;
{{ item.subject }}
<span v-if="item.showName" class="text-sm">(#{{ item.name }})</span>
</span>
<span
v-if="item.modified"
Expand Down
37 changes: 25 additions & 12 deletions helpdesk/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,18 @@ class HelpdeskSearch(Search):
{"name": "creation", "sortable": True},
]

DOCTYPE_FIELDS = {
"HD Ticket": ["name", "subject", "description", "agent_group", "modified", "creation",],
"HD Article": ["name", "category", "title", "content", "modified", "creation", "author", "category.category_name as category"],
}

def __init__(self):
super().__init__("helpdesk_idx", "search_doc", self.schema)

def build_index(self):
self.drop_index()
self.create_index()
records = self.get_records()
records = self.get_records("HD Ticket") + self.get_records("HD Article")
total = len(records)
for i, doc in enumerate(records):
self.index_doc(doc)
Expand All @@ -161,27 +166,32 @@ def index_doc(self, doc):
"subject": doc.subject,
"team": doc.agent_group,
}
if doc.doctype == "HD Article":
fields = {
"doctype": doc.doctype,
"name": doc.name,
"subject": doc.title,
"description": doc.content,
"modified": doc.modified,
}
payload = {
"author": doc.author,
"category": doc.category,
}
if fields and payload:
self.add_document(id, fields, payload)

def remove_doc(self, doc):
key = f"{doc.doctype}:{doc.name}"
self.remove_document(key)

def get_records(self):
def get_records(self, doctype):
records = []
for d in frappe.db.get_all(
"HD Ticket",
fields=[
"name",
"subject",
"description",
"agent_group",
"modified",
"creation",
],
doctype,
fields=self.DOCTYPE_FIELDS[doctype]
):
d.doctype = "HD Ticket"
d.doctype = doctype
records.append(d)
return records

Expand All @@ -205,6 +215,9 @@ def search(query):
r.name = name
if doctype == "HD Ticket":
groups.setdefault("Tickets", []).append(r)
elif doctype == "HD Article":
groups.setdefault("Articles", []).append(r)

out = []
for key in groups:
out.append({"title": key, "items": groups[key]})
Expand Down