feat: boosted active subjects + visual indication of inactive subjects

This commit is contained in:
SethBurkart123
2025-05-21 00:01:36 +10:00
parent d8512e44cf
commit bff48f0397
3 changed files with 61 additions and 43 deletions
@@ -17,7 +17,7 @@ import type { IndexItem } from '../../indexing/types';
{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'}" {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'}"
onclick={onclick} onclick={onclick}
> >
<div class="flex items-center w-full"> <div class="flex items-center w-full {item.metadata.isActive ? 'opacity-100' : 'opacity-70'}">
<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' ? '\ueac3' : '\ueb4d'} {item.metadata?.type === 'assessments' ? '\ueac3' : '\ueb4d'}
</div> </div>
@@ -25,12 +25,10 @@ export const subjectsJob: Job = {
score += 20; // Boost score for direct subject matches score += 20; // Boost score for direct subject matches
} }
// Boost for active subjects if (item.metadata.isActive) {
if (item.metadata?.isActive) {
score += 15; // Boost for active subjects score += 15; // Boost for active subjects
console.log("active subject:", item.metadata.subjectName);
} else { } else {
console.log("inactive subject:", item.metadata.subjectName); score -= 50; // Penalty for inactive subjects
} }
return score; return score;
@@ -83,8 +81,7 @@ export const subjectsJob: Job = {
const isActive = semester.active === 1; const isActive = semester.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( const assessmentsItem = {
{
id: `${id}-assessments`, id: `${id}-assessments`,
text: `${subject.title} Assessments`, text: `${subject.title} Assessments`,
category: "subjects", category: "subjects",
@@ -102,8 +99,9 @@ export const subjectsJob: Job = {
}, },
actionId: "subjectassessment", actionId: "subjectassessment",
renderComponentId: "subject", renderComponentId: "subject",
}, };
{
const courseItem = {
id: `${id}-course`, id: `${id}-course`,
text: `${subject.title} Course`, text: `${subject.title} Course`,
category: "subjects", category: "subjects",
@@ -121,7 +119,15 @@ export const subjectsJob: Job = {
}, },
actionId: "subjectcourse", actionId: "subjectcourse",
renderComponentId: "subject", renderComponentId: "subject",
} };
// Log all subject items during indexing
console.log('Indexing subject:', assessmentsItem.text, assessmentsItem.metadata.isActive);
console.log('Indexing subject:', courseItem.text, courseItem.metadata.isActive);
items.push(
assessmentsItem,
courseItem
); );
} }
} }
@@ -167,6 +167,18 @@ export async function performSearch(
// Add dynamic results first // Add dynamic results first
dynamicResults.forEach((r) => { dynamicResults.forEach((r) => {
seenIds.add(r.id); seenIds.add(r.id);
if (r.type === "dynamic") {
const dynamicItem = r.item as IndexItem;
const job = jobs[dynamicItem.category];
if (job && typeof job.boostCriteria === 'function') {
const boost = job.boostCriteria(dynamicItem, query);
if (boost) {
r.score += boost; // Add the boost to the score
}
}
}
const vectorMatch = vectorResults.find((v) => v.object.id === r.id); const vectorMatch = vectorResults.find((v) => v.object.id === r.id);
if (vectorMatch) { if (vectorMatch) {
// If we found it in both searches, combine the scores // If we found it in both searches, combine the scores