Skip to content

Commit

Permalink
Add glossary words
Browse files Browse the repository at this point in the history
  • Loading branch information
max-lt committed Dec 20, 2024
1 parent f764e67 commit a15c5bd
Showing 1 changed file with 54 additions and 16 deletions.
70 changes: 54 additions & 16 deletions packages/service-content/src/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const getCoursesQuery = () => sql<Searchable[]>`
LOWER(language) as language,
name as title,
raw_description as body,
CONCAT('/', language, '/courses/', course_id) as link
CONCAT(
'/',
language,
'/courses/',
course_id
) as link
FROM content.courses_localized ;
`;

Expand All @@ -32,7 +37,14 @@ const getCoursePartsQuery = () => sql<Searchable[]>`
cp.part_id,
first_chapter.chapter_id as first_chapter_id,
LOWER(language) as language,
CONCAT('/', language, '/courses/', cp.course_id, '/', first_chapter.chapter_id) as link,
CONCAT(
'/',
language,
'/courses/',
cp.course_id,
'/',
first_chapter.chapter_id
) as link,
cp.title,
'' as body
FROM content.course_parts_localized cp
Expand All @@ -46,7 +58,14 @@ const getCourseChaptersQuery = () => sql<Searchable[]>`
SELECT
'course_chapter' as type,
LOWER(language) as language,
CONCAT('/', language, '/courses/', course_id, '/', chapter_id) as link,
CONCAT(
'/',
language,
'/courses/',
course_id,
'/',
chapter_id
) as link,
title,
raw_content as body
FROM content.course_chapters_localized
Expand Down Expand Up @@ -81,7 +100,16 @@ const getTutorialsQuery = () => sql<Searchable[]>`
LOWER(language) as language,
title,
COALESCE(description, '') as body,
CONCAT('/', language, '/tutorials/', category, '/', subcategory, '/', tutorial_id) as link
CONCAT(
'/',
language,
'/tutorials/',
category,
'/',
subcategory,
'/',
tutorial_id
) as link
FROM content.tutorials_localized
JOIN content.tutorials t ON t.id = tutorial_id
`;
Expand All @@ -94,7 +122,12 @@ const getBooksQuery = () => sql<Searchable[]>`
CONCAT(author, ': ', title) as title,
original,
description as body,
CONCAT('/', language, '/resources/books/', book_id) as link
CONCAT(
'/',
language,
'/resources/books/',
book_id
) as link
FROM content.books_localized
JOIN content.books b ON b.resource_id = book_id
`;
Expand All @@ -116,6 +149,21 @@ const getPodcastsQuery = () => sql<Searchable[]>`
FROM content.podcasts
`;

const getGlossaryQuery = () => sql<Searchable[]>`
SELECT
'glossary_word' as type,
LOWER(language) as language,
term as title,
definition as body,
CONCAT(
'/',
language,
'/resources/glossary/',
LOWER(REPLACE(term, ' ', '-'))
) as link
FROM content.glossary_words_localized
`;

const createInitIndexes = (client: TypesenseClient) => () => {
const searchableSchema: CollectionCreateSchema = {
name: 'searchable',
Expand Down Expand Up @@ -178,17 +226,7 @@ export const createIndexContent = ({ postgres, typesense }: Dependencies) => {
...(await postgres.exec(getTutorialsQuery())),
...(await postgres.exec(getBooksQuery())),
...(await postgres.exec(getPodcastsQuery())),
// Test data
{
type: 'course_chapter',
course_id: 0,
chapter_id: 0,
language: 'en' as Language,
title: 'Hello world, test the testing search for testing',
body: 'Hello world, test the testing search for testing',
link: '/en/courses/0',
dummy: 'value',
},
...(await postgres.exec(getGlossaryQuery())),
];

await ingestData(data);
Expand Down

0 comments on commit a15c5bd

Please sign in to comment.