feat: improved search results in command palette
This commit is contained in:
29
lms/command_palette.py
Normal file
29
lms/command_palette.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import frappe
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def search_sqlite(query: str):
|
||||
from lms.sqlite import LearningSearch, LearningSearchIndexMissingError
|
||||
|
||||
search = LearningSearch()
|
||||
|
||||
try:
|
||||
result = search.search(query)
|
||||
except LearningSearchIndexMissingError:
|
||||
return []
|
||||
|
||||
groups = {}
|
||||
print(result)
|
||||
for r in result["results"]:
|
||||
doctype = r["doctype"]
|
||||
|
||||
if doctype == "LMS Course":
|
||||
groups.setdefault("Courses", []).append(r)
|
||||
elif doctype == "LMS Batch":
|
||||
groups.setdefault("Batches", []).append(r)
|
||||
|
||||
out = []
|
||||
for key in groups:
|
||||
out.append({"title": key, "items": groups[key]})
|
||||
|
||||
return out
|
||||
Reference in New Issue
Block a user