fix(sorting): re-work sorting system to use api response more effectivly, and some styling improvements

This commit is contained in:
2025-05-11 13:27:58 +09:30
parent ed767131ad
commit 27f357cc82
3 changed files with 25 additions and 15 deletions
@@ -46,7 +46,7 @@
> >
<div class="flex items-center w-full"> <div class="flex items-center w-full">
<div class="flex-none w-8 h-8 text-xl font-IconFamily flex items-center justify-center {isSelected ? 'text-zinc-900 dark:text-white' : 'text-zinc-600 dark:text-zinc-400'}"> <div class="flex-none w-8 h-8 text-xl font-IconFamily flex items-center justify-center {isSelected ? 'text-zinc-900 dark:text-white' : 'text-zinc-600 dark:text-zinc-400'}">
{item.metadata?.type === 'assessments' ? '\uebee' : '\uec0a'} {item.metadata?.type === 'assessments' ? '\ueac3' : '\ueb4d'}
</div> </div>
<span class="ml-4 text-lg truncate"> <span class="ml-4 text-lg truncate">
{@html stripHtmlButKeepHighlights(highlightMatch(item.text, searchTerm, matches))} {@html stripHtmlButKeepHighlights(highlightMatch(item.text, searchTerm, matches))}
@@ -63,6 +63,10 @@ export const subjectsJob: Job = {
const id = `${semester.code}-${subject.code}-${subject.metaclass}`; const id = `${semester.code}-${subject.code}-${subject.metaclass}`;
if (existingIds.has(id)) continue; if (existingIds.has(id)) continue;
// Extract year level from subject code (assuming format like "YEAR10" or "10ENG")
const yearLevel = subject.code.match(/^YEAR(\d+)|^(\d+)/i)?.[1] || subject.code.match(/^(\d+)/)?.[1] || 0;
const isActive = subject.active === 1;
// Create two items for each subject - one for assessments and one for course // Create two items for each subject - one for assessments and one for course
items.push( items.push(
{ {
@@ -78,7 +82,9 @@ export const subjectsJob: Job = {
programme: subject.programme, programme: subject.programme,
semesterCode: semester.code, semesterCode: semester.code,
semesterDescription: semester.description, semesterDescription: semester.description,
type: "assessments" type: "assessments",
yearLevel: Number(yearLevel),
isActive
}, },
actionId: "subject-assessments", actionId: "subject-assessments",
renderComponentId: "subject", renderComponentId: "subject",
@@ -96,7 +102,9 @@ export const subjectsJob: Job = {
programme: subject.programme, programme: subject.programme,
semesterCode: semester.code, semesterCode: semester.code,
semesterDescription: semester.description, semesterDescription: semester.description,
type: "course" type: "course",
yearLevel: Number(yearLevel),
isActive
}, },
actionId: "subject-course", actionId: "subject-course",
renderComponentId: "subject", renderComponentId: "subject",
@@ -25,15 +25,16 @@ export function createSearchIndexes() {
{ name: "content", weight: 1 }, { name: "content", weight: 1 },
{ name: "category", weight: 1 }, { name: "category", weight: 1 },
{ name: "metadata.subjectName", weight: 3 }, { name: "metadata.subjectName", weight: 3 },
{ name: "metadata.subjectCode", weight: 2 }, { name: "metadata.subjectCode", weight: 2.5 },
{ name: "metadata.semesterDescription", weight: 1 } { name: "metadata.semesterDescription", weight: 1 },
{ name: "metadata.yearLevel", weight: 1.5 }
], ],
includeScore: true, includeScore: true,
includeMatches: true, includeMatches: true,
threshold: 0.4, // Lower threshold to be more lenient threshold: 0.4,
minMatchCharLength: 2, minMatchCharLength: 2,
distance: 100, // Increased distance to allow for more fuzzy matches distance: 100,
useExtendedSearch: true, // Enable extended search for better matching useExtendedSearch: true,
}; };
return { return {
@@ -123,14 +124,15 @@ export function searchDynamicItems(
if (hasSubjectMatch) { if (hasSubjectMatch) {
score += 20; // Boost score for direct subject matches score += 20; // Boost score for direct subject matches
} }
// Boost for higher year levels
const yearMatch = /^Year (\d+)/i.exec(item.metadata?.subjectName || ""); // Boost for active subjects
if (yearMatch) { if (item.metadata?.isActive) {
const yearNum = parseInt(yearMatch[1], 10); score += 15; // Boost for active subjects
if (!isNaN(yearNum)) {
score += yearNum; // Boost by year number
}
} }
// Boost for year level
const yearLevel = item.metadata?.yearLevel || 0;
score += yearLevel; // Add year level to score
} }
const ageInDays = (now - item.dateAdded) / (1000 * 60 * 60 * 24); const ageInDays = (now - item.dateAdded) / (1000 * 60 * 60 * 24);