Add searchable lyrics index

This commit is contained in:
Jonathan Sykes
2026-10-14 02:10:02 +08:00
parent e3821621f3
commit 11b10e38e2
6 changed files with 209 additions and 2 deletions

View File

@@ -93,4 +93,23 @@ describe('lyrics quality queue', () => {
expect(dump.status).toBe(200);
expect(await dump.text()).toContain('CREATE TABLE');
});
test('lyrics search is indexed on save, filters chapter state, and rebuilds under admin auth', async () => {
const id = 'SearchSong01';
await db.db.execute({ sql: 'INSERT INTO video_meta(id,card,hay,seen,updated_at) VALUES(?,?,?,?,?)', args: [id, JSON.stringify({ title: 'Amazing grace sample', channel: 'Choir' }), 'amazing grace sample choir', 1, Date.now()] });
await db.saveNote({ videoId: id, kind: 'lyrics', data: { lines: [{ t: 1, text: 'Amazing grace will lead me home' }] }, source: 'user', force: true });
expect((await app.request('/api/admin/lyrics/search?q=amazing')).status).toBe(401);
const headers = { 'x-admin': 'yes' };
let result = await (await app.request('/api/admin/lyrics/search?q=amazing+grace&hasChapters=no', { headers })).json();
expect(result.results[0]).toMatchObject({ videoId: id, title: 'Amazing grace sample', hasChapters: false });
expect(result.results[0].snippet).toContain('\u0001');
await db.saveNote({ videoId: id, kind: 'chapters', data: { items: [{ t: 1, title: 'Verse' }] }, source: 'user', force: true });
result = await (await app.request('/api/admin/lyrics/search?q=amazing&hasChapters=yes', { headers })).json();
expect(result.results[0].videoId).toBe(id);
await db.saveNote({ videoId: id, kind: 'lyrics', data: { lines: [{ t: 1, text: 'Bright morning star' }] }, source: 'user', force: true });
expect((await (await app.request('/api/admin/lyrics/search?q=amazing', { headers })).json()).total).toBe(0);
const rebuilt = await (await app.request('/api/admin/lyrics/search/rebuild', { method: 'POST', headers: { ...headers, 'content-type': 'application/json' }, body: '{}' })).json();
expect(rebuilt.ok).toBe(true);
expect(rebuilt.indexed).toBeGreaterThanOrEqual(1);
});
});