Wiki Phase 4: full-text search + revision history
Final phase of the wiki upgrade (see WIKI_UPGRADE.md). Schema (additive): wiki_revisions table (per-save content snapshots). The FULLTEXT index on wiki_pages(title, body) shipped in Phase 1. Search: - MATCH ... AGAINST natural-language search over title + body, ordered by relevance - public: GET /public/wiki?q= (published only); admin: GET /admin/wiki?q= (all statuses) - public wiki index gains a search box; admin list gains a search field Revision history: - every create/update snapshots the page into wiki_revisions - admin endpoints: list revisions, get one, and restore (restore overwrites the page, rebuilds links, and appends a new revision — history stays append-only); logged as wiki.revision.restore - editor gains a History modal: revision list + word-level diff (jsdiff) of a chosen revision against the current page, with one-click restore Verified end-to-end: search matches body and title; two edits produce three revisions; diff renders added/removed words; restore reverts and records a new revision. No console errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,17 @@ async function findPublishedBySlug(slug) {
|
||||
return rows[0] || null
|
||||
}
|
||||
|
||||
// Full-text search over title + body, ordered by relevance.
|
||||
async function searchSummaries(q, { publishedOnly = true } = {}) {
|
||||
const pub = publishedOnly ? 'AND p.published = 1' : ''
|
||||
return query(
|
||||
`SELECT ${SUMMARY_COLS} ${FROM}
|
||||
WHERE MATCH(p.title, p.body) AGAINST (? IN NATURAL LANGUAGE MODE) ${pub}
|
||||
ORDER BY MATCH(p.title, p.body) AGAINST (?) DESC, p.title ASC`,
|
||||
[q, q],
|
||||
)
|
||||
}
|
||||
|
||||
// ── Page writes ────────────────────────────────────────────────────────
|
||||
async function insert({
|
||||
slug,
|
||||
@@ -233,6 +244,29 @@ async function getExistingSlugs(slugs) {
|
||||
return new Set(rows.map((r) => r.slug))
|
||||
}
|
||||
|
||||
// ── Revisions ──────────────────────────────────────────────────────────
|
||||
async function insertRevision({ pageId, title, body, excerpt, categoryId, editorId, changeNote }) {
|
||||
return query(
|
||||
'INSERT INTO wiki_revisions (page_id, title, body, excerpt, category_id, editor_id, change_note) ' +
|
||||
'VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
[pageId, title, body || null, excerpt || null, categoryId ?? null, editorId ?? null, changeNote || null],
|
||||
)
|
||||
}
|
||||
|
||||
async function listRevisions(pageId) {
|
||||
return query(
|
||||
`SELECT r.id, r.change_note, r.created_at, r.editor_id, u.username AS editor
|
||||
FROM wiki_revisions r LEFT JOIN users u ON u.id = r.editor_id
|
||||
WHERE r.page_id = ? ORDER BY r.id DESC`,
|
||||
[pageId],
|
||||
)
|
||||
}
|
||||
|
||||
async function findRevision(id) {
|
||||
const rows = await query('SELECT * FROM wiki_revisions WHERE id = ? LIMIT 1', [id])
|
||||
return rows[0] || null
|
||||
}
|
||||
|
||||
// ── Seeding (idempotent) ───────────────────────────────────────────────
|
||||
async function seedDefault(slug, title, body) {
|
||||
await query('INSERT IGNORE INTO wiki_pages (slug, title, body) VALUES (?, ?, ?)', [
|
||||
@@ -264,6 +298,7 @@ module.exports = {
|
||||
listAllSummaries,
|
||||
findBySlug,
|
||||
findPublishedBySlug,
|
||||
searchSummaries,
|
||||
insert,
|
||||
updateBySlug,
|
||||
deleteBySlug,
|
||||
@@ -283,6 +318,9 @@ module.exports = {
|
||||
insertLink,
|
||||
getBacklinks,
|
||||
getExistingSlugs,
|
||||
insertRevision,
|
||||
listRevisions,
|
||||
findRevision,
|
||||
seedDefault,
|
||||
seedDefaultCategory,
|
||||
assignCategoryBySlug,
|
||||
|
||||
Reference in New Issue
Block a user