Add drag reordering, exam deadlines, frozen shared quizzes, batched OCR and semantic search
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
- Drag-to-reorder for class materials, folders, quiz questions and deck cards. Pointer-based so touch works, plus keyboard (arrows/Home/End) with screen-reader announcements. - Timed exams get a wall-clock deadline. The server refuses late answers, submits overdue exams with what was saved, and the countdown keeps running while the page is closed. - Shared quiz sessions keep a frozen copy of their questions and flag later owner edits. - Scanned PDFs are read in cached 8-page batches with real page numbers (pdf-lib), removing the 30 MB whole-file limit. Compatible providers now receive PDFs as file parts. - Semantic search: embeddings for OpenAI, Gemini, Ollama and compatible servers, background indexing into chunk_vectors (migration 2), hybrid keyword + vector ranking for search, the assistant and focused generation, and a Settings -> AI section. 181 tests pass locally and in the Docker test stage on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3046e46d1c
commit
ccdad9728b
39 changed files with 1772 additions and 121 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { Hono } from 'hono';
|
||||
import { getEmbeddingSettings, semanticSearch } from '../services/semantic.ts';
|
||||
import { z } from 'zod';
|
||||
import { badRequest, idParam, readBody, type AppContext } from '../http.ts';
|
||||
import { getAppSettings } from '../settings.ts';
|
||||
|
|
@ -125,14 +126,14 @@ export function studyRoutes(app: AppContext): Hono {
|
|||
|
||||
/* ------------------------------ search ------------------------------ */
|
||||
|
||||
r.get('/search', (c) => {
|
||||
r.get('/search', async (c) => {
|
||||
const q = (c.req.query('q') ?? '').trim().slice(0, 120);
|
||||
if (q.length < 2) return c.json({ query: q, results: [] });
|
||||
const like = `%${q.replace(/[\\%_]/g, (m) => `\\${m}`)}%`;
|
||||
const classId = c.req.query('classId') || null;
|
||||
const scoped = (col: string) => (classId ? `AND ${col} = ?` : '');
|
||||
const p = (...base: string[]) => (classId ? [...base, classId] : base);
|
||||
type Hit = { kind: string; id: string; title: string; snippet: string; classId: string; className: string; classColor: string; parentId?: string; page?: number | null };
|
||||
type Hit = { kind: string; id: string; title: string; snippet: string; classId: string; className: string; classColor: string; parentId?: string; page?: number | null; semantic?: boolean };
|
||||
const results: Hit[] = [];
|
||||
|
||||
for (const row of db.all<Record<string, string>>(`SELECT id, name, color FROM classes WHERE name LIKE ? ESCAPE '\\' OR code LIKE ? ESCAPE '\\' LIMIT 5`, like, like)) {
|
||||
|
|
@ -184,6 +185,25 @@ export function studyRoutes(app: AppContext): Hono {
|
|||
/* a malformed FTS query should never break search */
|
||||
}
|
||||
}
|
||||
// Passages that match the meaning rather than the words (when semantic search is set up).
|
||||
// Only for phrases or longer terms: single short words are already well served by keywords.
|
||||
if ((/\s/.test(q) || q.length >= 8) && getEmbeddingSettings(db).providerId) {
|
||||
try {
|
||||
const seen = new Set(results.filter((r) => r.kind === 'passage').map((r) => r.id));
|
||||
for (const hit of await semanticSearch(app, q, { classId }, 6, 0.35)) {
|
||||
if (seen.has(String(hit.id))) continue;
|
||||
const doc = db.get<Record<string, string>>(
|
||||
'SELECT k.id AS class_id, k.name AS class_name, k.color AS class_color FROM documents d JOIN classes k ON k.id = d.class_id WHERE d.id = ?',
|
||||
hit.documentId,
|
||||
);
|
||||
if (!doc) continue;
|
||||
const text = hit.text.replace(/\s+/g, ' ').trim();
|
||||
results.push({ kind: 'passage', id: String(hit.id), parentId: hit.documentId, page: hit.pageStart, title: hit.documentTitle, snippet: text.length > 160 ? `${text.slice(0, 160)} …` : text, classId: doc.class_id, className: doc.class_name, classColor: doc.class_color, semantic: true });
|
||||
}
|
||||
} catch (err) {
|
||||
app.log('warn', `Semantic search failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}
|
||||
return c.json({ query: q, results });
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue