mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
fix: incorrect usage and cleanup
This commit is contained in:
@@ -196,15 +196,6 @@
|
||||
const result = combinedResults[resultIndex];
|
||||
if (result?.item) {
|
||||
executeItemAction(result.item);
|
||||
if (result?.type === 'dynamic') {
|
||||
tick().then(() => {
|
||||
const li = resultsList?.querySelectorAll('li')[resultIndex];
|
||||
if (li) {
|
||||
const btn = li.querySelector('button, [tabindex="0"]');
|
||||
if (btn) (btn as HTMLElement).click();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -306,7 +297,7 @@
|
||||
searchTerm={searchTerm}
|
||||
matches={result.matches}
|
||||
onclick={() => executeItemAction(dynamicItem)}
|
||||
onkeydown={() => {}}
|
||||
onkeydown={() => executeItemAction(dynamicItem)}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
/>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<button
|
||||
class="w-full flex flex-col px-2 py-1.5 rounded-lg select-none cursor-pointer group transition-colors duration-100
|
||||
{isSelected ? 'bg-zinc-900/5 dark:bg-white/10 text-zinc-900 dark:text-white' : 'hover:bg-zinc-500/5 dark:hover:bg-white/5 text-zinc-800 dark:text-zinc-200'}"
|
||||
on:click={() => { handleClick(); if (typeof onclick === 'function') onclick(); }}
|
||||
onclick={() => { handleClick(); if (typeof onclick === 'function') onclick(); }}
|
||||
>
|
||||
<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'}">
|
||||
|
||||
@@ -37,4 +37,12 @@ export const actionMap: Record<string, ActionHandler<any>> = {
|
||||
window.location.hash = `#?page=/assessments&id=${item.metadata.assessmentId}`;
|
||||
}
|
||||
}) as ActionHandler<any>,
|
||||
|
||||
subjectassessment: ((item: IndexItem) => {
|
||||
window.location.href = `/#?page=/assessments/${item.metadata.programme}:${item.metadata.subjectId}`;
|
||||
}) as ActionHandler<any>,
|
||||
|
||||
subjectcourse: ((item: IndexItem) => {
|
||||
window.location.href = `/#?page=/courses/${item.metadata.programme}:${item.metadata.subjectId}`;
|
||||
}) as ActionHandler<any>,
|
||||
};
|
||||
|
||||
@@ -18,6 +18,24 @@ export const subjectsJob: Job = {
|
||||
label: "Subjects",
|
||||
renderComponentId: "subject",
|
||||
frequency: "pageLoad",
|
||||
boostCriteria: (item, searchTerm) => {
|
||||
let score = 0;
|
||||
const hasSubjectMatch = searchTerm.toLowerCase().includes(item.metadata.subjectName.toLowerCase()) || searchTerm.toLowerCase().includes(item.metadata.subjectCode.toLowerCase());
|
||||
if (hasSubjectMatch) {
|
||||
score += 20; // Boost score for direct subject matches
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
return score;
|
||||
},
|
||||
|
||||
run: async (ctx) => {
|
||||
const existingIds = new Set(
|
||||
@@ -83,10 +101,10 @@ export const subjectsJob: Job = {
|
||||
semesterCode: semester.code,
|
||||
semesterDescription: semester.description,
|
||||
type: "assessments",
|
||||
yearLevel: Number(yearLevel),
|
||||
yearLevel: yearLevel ? Number(yearLevel) : 0,
|
||||
isActive
|
||||
},
|
||||
actionId: "subject-assessments",
|
||||
actionId: "subjectassessment",
|
||||
renderComponentId: "subject",
|
||||
},
|
||||
{
|
||||
@@ -103,10 +121,10 @@ export const subjectsJob: Job = {
|
||||
semesterCode: semester.code,
|
||||
semesterDescription: semester.description,
|
||||
type: "course",
|
||||
yearLevel: Number(yearLevel),
|
||||
yearLevel: yearLevel ? Number(yearLevel) : 0,
|
||||
isActive
|
||||
},
|
||||
actionId: "subject-course",
|
||||
actionId: "subjectcourse",
|
||||
renderComponentId: "subject",
|
||||
}
|
||||
);
|
||||
|
||||
@@ -33,4 +33,5 @@ export interface Job {
|
||||
renderComponentId: string;
|
||||
run: (ctx: JobContext) => Promise<IndexItem[]>;
|
||||
purge?: (items: IndexItem[]) => IndexItem[];
|
||||
boostCriteria?: (item: IndexItem, searchTerm: string) => number;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { CombinedResult } from "../core/types";
|
||||
import type { IndexItem } from "../indexing/types";
|
||||
import { searchVectors } from "./vector/vectorSearch";
|
||||
import type { VectorSearchResult } from "./vector/vectorTypes";
|
||||
import { jobs } from "../indexing/jobs";
|
||||
|
||||
export function createSearchIndexes() {
|
||||
const commands = getStaticCommands();
|
||||
@@ -114,25 +115,12 @@ export function searchDynamicItems(
|
||||
const item = result.item;
|
||||
const fuseScore = 10 * (1 - (result.score || 0.5));
|
||||
|
||||
// Boost score for subject matches
|
||||
let score = fuseScore;
|
||||
if (item.category === "subjects") {
|
||||
// Check if the match is in subjectName or subjectCode
|
||||
const hasSubjectMatch = result.matches?.some(match =>
|
||||
match.key === "metadata.subjectName" || match.key === "metadata.subjectCode"
|
||||
);
|
||||
if (hasSubjectMatch) {
|
||||
score += 20; // Boost score for direct subject matches
|
||||
}
|
||||
|
||||
// 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
|
||||
// apply boost criteria if it exists
|
||||
const boost = jobs[item.category].boostCriteria?.(item, query);
|
||||
if (boost) {
|
||||
score += boost;
|
||||
}
|
||||
|
||||
const ageInDays = (now - item.dateAdded) / (1000 * 60 * 60 * 24);
|
||||
|
||||
Reference in New Issue
Block a user