feat: search by instructor name from command palette
This commit is contained in:
@@ -79,7 +79,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="
|
v-if="
|
||||||
result.published_on || result.start_date || result.creation
|
result.published_on ||
|
||||||
|
result.start_date ||
|
||||||
|
result.creation ||
|
||||||
|
result.modified
|
||||||
"
|
"
|
||||||
class="ml-auto text-sm text-ink-gray-5"
|
class="ml-auto text-sm text-ink-gray-5"
|
||||||
>
|
>
|
||||||
@@ -87,7 +90,8 @@
|
|||||||
dayjs(
|
dayjs(
|
||||||
result.published_on ||
|
result.published_on ||
|
||||||
result.start_date ||
|
result.start_date ||
|
||||||
result.creation
|
result.creation ||
|
||||||
|
result.modified
|
||||||
).format('DD MMM YYYY')
|
).format('DD MMM YYYY')
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
@@ -164,7 +168,7 @@ const generateSearchResults = () => {
|
|||||||
searchResults.value.push(item)
|
searchResults.value.push(item)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
searchResults.value.sort((a, b) => b.score - a.score)
|
//searchResults.value.sort((a, b) => b.score - a.score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,25 @@ def prepare_search_results(result):
|
|||||||
|
|
||||||
out = []
|
out = []
|
||||||
for key in groups:
|
for key in groups:
|
||||||
|
groups[key] = remove_duplicates(groups[key])
|
||||||
|
groups[key].sort(key=lambda x: x.get("modified"), reverse=True)
|
||||||
out.append({"title": key, "items": groups[key]})
|
out.append({"title": key, "items": groups[key]})
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def remove_duplicates(items):
|
||||||
|
seen = set()
|
||||||
|
unique_items = []
|
||||||
|
for item in items:
|
||||||
|
if item["name"] not in seen:
|
||||||
|
seen.add(item["name"])
|
||||||
|
unique_items.append(item)
|
||||||
|
return unique_items
|
||||||
|
|
||||||
|
|
||||||
def can_access_course(course, roles):
|
def can_access_course(course, roles):
|
||||||
|
print(course.get("name"), course.get("published"))
|
||||||
if can_create_course(roles):
|
if can_create_course(roles):
|
||||||
return True
|
return True
|
||||||
elif course.get("published"):
|
elif course.get("published"):
|
||||||
@@ -73,10 +86,14 @@ def get_instructor_info(doctype, record):
|
|||||||
instructors = frappe.get_all(
|
instructors = frappe.get_all(
|
||||||
"Course Instructor", filters={"parenttype": doctype, "parent": record.get("name")}, pluck="instructor"
|
"Course Instructor", filters={"parenttype": doctype, "parent": record.get("name")}, pluck="instructor"
|
||||||
)
|
)
|
||||||
|
|
||||||
instructor = record.get("author")
|
instructor = record.get("author")
|
||||||
if len(instructors):
|
if len(instructors):
|
||||||
instructor = instructors[0]
|
for ins in instructors:
|
||||||
|
if ins.split("@")[0] in record.get("content"):
|
||||||
|
instructor = ins
|
||||||
|
break
|
||||||
|
if not instructor:
|
||||||
|
instructor = instructors[0]
|
||||||
|
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(
|
||||||
"User",
|
"User",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from contextlib import suppress
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.search.sqlite_search import SQLiteSearch, SQLiteSearchIndexMissingError
|
from frappe.search.sqlite_search import SQLiteSearch, SQLiteSearchIndexMissingError
|
||||||
from frappe.utils import nowdate
|
from frappe.utils import get_datetime, nowdate
|
||||||
|
|
||||||
|
|
||||||
class LearningSearch(SQLiteSearch):
|
class LearningSearch(SQLiteSearch):
|
||||||
@@ -17,6 +17,8 @@ class LearningSearch(SQLiteSearch):
|
|||||||
"status",
|
"status",
|
||||||
"company_name",
|
"company_name",
|
||||||
"creation",
|
"creation",
|
||||||
|
"parent",
|
||||||
|
"parenttype",
|
||||||
],
|
],
|
||||||
"tokenizer": "unicode61 remove_diacritics 2 tokenchars '-_'",
|
"tokenizer": "unicode61 remove_diacritics 2 tokenchars '-_'",
|
||||||
}
|
}
|
||||||
@@ -60,6 +62,16 @@ class LearningSearch(SQLiteSearch):
|
|||||||
{"modified": "creation"},
|
{"modified": "creation"},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
"Course Instructor": {
|
||||||
|
"fields": [
|
||||||
|
"name",
|
||||||
|
{"title": "instructor"},
|
||||||
|
{"content": "instructor"},
|
||||||
|
"parent",
|
||||||
|
"parenttype",
|
||||||
|
"modified",
|
||||||
|
]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
DOCTYPE_FIELDS = {
|
DOCTYPE_FIELDS = {
|
||||||
@@ -92,6 +104,12 @@ class LearningSearch(SQLiteSearch):
|
|||||||
"modified",
|
"modified",
|
||||||
"owner",
|
"owner",
|
||||||
],
|
],
|
||||||
|
"Course Instructor": [
|
||||||
|
"name",
|
||||||
|
"instructor",
|
||||||
|
"parent",
|
||||||
|
"parenttype",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
def build_index(self):
|
def build_index(self):
|
||||||
@@ -103,6 +121,63 @@ class LearningSearch(SQLiteSearch):
|
|||||||
def get_search_filters(self):
|
def get_search_filters(self):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def prepare_document(self, doc):
|
||||||
|
document = super().prepare_document(doc)
|
||||||
|
if not document:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if doc.doctype == "Course Instructor":
|
||||||
|
instructor = frappe.db.get_value("User", doc.instructor, "full_name")
|
||||||
|
if doc.parenttype == "LMS Course":
|
||||||
|
details = frappe.db.get_value(
|
||||||
|
"LMS Course",
|
||||||
|
doc.parent,
|
||||||
|
["name", "title", "description", "published_on", "modified", "published"],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
document["published_on"] = details.get("published_on")
|
||||||
|
elif doc.parenttype == "LMS Batch":
|
||||||
|
details = frappe.db.get_value(
|
||||||
|
"LMS Batch",
|
||||||
|
doc.parent,
|
||||||
|
["name", "title", "batch_details as description", "start_date", "modified", "published"],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
document["start_date"] = details.get("start_date")
|
||||||
|
|
||||||
|
if details:
|
||||||
|
document["doctype"] = doc.parenttype
|
||||||
|
document["name"] = doc.parent
|
||||||
|
document["title"] = self._process_content(details.title)
|
||||||
|
document["content"] = self._process_content(
|
||||||
|
f"Instructor: {instructor}\n{details.description}\n{doc.instructor}"
|
||||||
|
)
|
||||||
|
document["modified"] = self.get_modified_date(details, doc.parenttype)
|
||||||
|
document["published"] = details.get("published", 0)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if not document.get("modified"):
|
||||||
|
document["modified"] = self.get_modified_date(doc, doc.doctype)
|
||||||
|
|
||||||
|
return document
|
||||||
|
|
||||||
|
def get_modified_date(self, details, doctype):
|
||||||
|
modified_value = None
|
||||||
|
if doctype == "LMS Course":
|
||||||
|
modified_value = details.get("published_on")
|
||||||
|
elif doctype == "LMS Batch":
|
||||||
|
modified_value = details.get("start_date")
|
||||||
|
|
||||||
|
if not modified_value:
|
||||||
|
modified_value = frappe.db.get_value(doctype, details.name, "creation")
|
||||||
|
print(details.name, modified_value)
|
||||||
|
|
||||||
|
modified_value = get_datetime(modified_value)
|
||||||
|
print(modified_value)
|
||||||
|
modified_value = modified_value.timestamp()
|
||||||
|
print(modified_value)
|
||||||
|
return modified_value
|
||||||
|
|
||||||
@SQLiteSearch.scoring_function
|
@SQLiteSearch.scoring_function
|
||||||
def get_doctype_boost(self, row, query, query_words):
|
def get_doctype_boost(self, row, query, query_words):
|
||||||
doctype = row["doctype"]
|
doctype = row["doctype"]
|
||||||
|
|||||||
Reference in New Issue
Block a user