Skip to content

Commit

Permalink
refactor: add new QB parser
Browse files Browse the repository at this point in the history
  • Loading branch information
PupoSDC committed Feb 5, 2024
1 parent 08ad1d1 commit ae733d3
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 777 deletions.
2 changes: 2 additions & 0 deletions libs/base/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export * from "./lib/question-bank-question-templates";
export * from "./lib/question-bank-subjects";
export * from "./lib/test";
export * from "./lib/test-questions";
export * from "./lib/mdx";
export * from "./lib/fs";
24 changes: 12 additions & 12 deletions libs/core/app/src/search/doc-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type {
SubjectId,
LearningObjectiveId,
} from "@chair-flight/base/types";
import type { QuestionBank } from "@chair-flight/core/question-bank";
import type { IQuestionBank } from "@chair-flight/core/question-bank";
import type { default as MiniSearch, SearchOptions } from "minisearch";

export type DocSearchField = "id" | "learningObjectiveId" | "content" | "title";
export type DocSearchField = "id" | "learningObjectives" | "content" | "title";
export type DocSearchDocument = Record<DocSearchField, string>;

export type DocSearchResult = {
Expand All @@ -19,10 +19,10 @@ export type DocSearchResult = {
subject: SubjectId;
empty: boolean;
href: string;
learningObjective: {
learningObjectives: Array<{
id: LearningObjectiveId;
href: string;
};
}>;
};

let initializationWork: Promise<void> | undefined;
Expand All @@ -36,7 +36,7 @@ export const searchDocsParams = z.object({
cursor: z.number().default(0),
});

export const getDocsSearchFilters = async (qb: QuestionBank) => {
export const getDocsSearchFilters = async (qb: IQuestionBank) => {
const rawSubjects = await qb.getAll("subjects");

const subject = [
Expand All @@ -61,7 +61,7 @@ export const populateDocsSearchIndex = async ({
searchIndex,
searchResults,
}: {
bank: QuestionBank;
bank: IQuestionBank;
searchIndex: MiniSearch<DocSearchDocument>;
searchResults: Map<string, DocSearchResult>;
}): Promise<void> => {
Expand All @@ -77,7 +77,7 @@ export const populateDocsSearchIndex = async ({

const searchItems: DocSearchDocument[] = docs.flatMap((doc) => ({
id: doc.id,
learningObjectiveId: doc.learningObjectiveId,
learningObjectives: doc.learningObjectives.join(", "),
content: doc.content,
title: doc.title,
}));
Expand All @@ -87,12 +87,12 @@ export const populateDocsSearchIndex = async ({
questionBank: bank.getName(),
title: doc.title,
empty: doc.empty,
subject: doc.subjectId,
subject: doc.subject,
href: `/modules/${bank.getName()}/docs/${doc.id}`,
learningObjective: {
id: doc.learningObjectiveId,
href: `/modules/${bank.getName()}/learning-objectives/${doc.learningObjectiveId}`,
},
learningObjectives: doc.learningObjectives.map((lo) => ({
id: lo,
href: `/modules/${bank.getName()}/learning-objectives/${lo}`,
})),
}));

await searchIndex.addAllAsync(searchItems);
Expand Down
5 changes: 5 additions & 0 deletions libs/core/question-bank/executors.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"executors": {
"arrange": {
"implementation": "./executors/arrange/executor",
"schema": "./executors/arrange/schema.json",
"description": "Arrange question Bankr"
},
"compile": {
"implementation": "./executors/compile/executor",
"schema": "./executors/compile/schema.json",
Expand Down
137 changes: 0 additions & 137 deletions libs/core/question-bank/executors/common/connect-question-bank.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit ae733d3

Please sign in to comment.