mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
fix(sorting): re-work sorting system to use api response more effectivly, and some styling improvements
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
>
|
||||
<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'}">
|
||||
{item.metadata?.type === 'assessments' ? '\uebee' : '\uec0a'}
|
||||
{item.metadata?.type === 'assessments' ? '\ueac3' : '\ueb4d'}
|
||||
</div>
|
||||
<span class="ml-4 text-lg truncate">
|
||||
{@html stripHtmlButKeepHighlights(highlightMatch(item.text, searchTerm, matches))}
|
||||
|
||||
@@ -63,6 +63,10 @@ export const subjectsJob: Job = {
|
||||
const id = `${semester.code}-${subject.code}-${subject.metaclass}`;
|
||||
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
|
||||
items.push(
|
||||
{
|
||||
@@ -78,7 +82,9 @@ export const subjectsJob: Job = {
|
||||
programme: subject.programme,
|
||||
semesterCode: semester.code,
|
||||
semesterDescription: semester.description,
|
||||
type: "assessments"
|
||||
type: "assessments",
|
||||
yearLevel: Number(yearLevel),
|
||||
isActive
|
||||
},
|
||||
actionId: "subject-assessments",
|
||||
renderComponentId: "subject",
|
||||
@@ -96,7 +102,9 @@ export const subjectsJob: Job = {
|
||||
programme: subject.programme,
|
||||
semesterCode: semester.code,
|
||||
semesterDescription: semester.description,
|
||||
type: "course"
|
||||
type: "course",
|
||||
yearLevel: Number(yearLevel),
|
||||
isActive
|
||||
},
|
||||
actionId: "subject-course",
|
||||
renderComponentId: "subject",
|
||||
|
||||
@@ -25,15 +25,16 @@ export function createSearchIndexes() {
|
||||
{ name: "content", weight: 1 },
|
||||
{ name: "category", weight: 1 },
|
||||
{ name: "metadata.subjectName", weight: 3 },
|
||||
{ name: "metadata.subjectCode", weight: 2 },
|
||||
{ name: "metadata.semesterDescription", weight: 1 }
|
||||
{ name: "metadata.subjectCode", weight: 2.5 },
|
||||
{ name: "metadata.semesterDescription", weight: 1 },
|
||||
{ name: "metadata.yearLevel", weight: 1.5 }
|
||||
],
|
||||
includeScore: true,
|
||||
includeMatches: true,
|
||||
threshold: 0.4, // Lower threshold to be more lenient
|
||||
threshold: 0.4,
|
||||
minMatchCharLength: 2,
|
||||
distance: 100, // Increased distance to allow for more fuzzy matches
|
||||
useExtendedSearch: true, // Enable extended search for better matching
|
||||
distance: 100,
|
||||
useExtendedSearch: true,
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -123,14 +124,15 @@ export function searchDynamicItems(
|
||||
if (hasSubjectMatch) {
|
||||
score += 20; // Boost score for direct subject matches
|
||||
}
|
||||
// Boost for higher year levels
|
||||
const yearMatch = /^Year (\d+)/i.exec(item.metadata?.subjectName || "");
|
||||
if (yearMatch) {
|
||||
const yearNum = parseInt(yearMatch[1], 10);
|
||||
if (!isNaN(yearNum)) {
|
||||
score += yearNum; // Boost by year number
|
||||
}
|
||||
|
||||
// Boost for active subjects
|
||||
if (item.metadata?.isActive) {
|
||||
score += 15; // Boost for active subjects
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user