add event clustering feature to group articles by similarity and time proximity

This commit is contained in:
ImBenji
2026-04-21 12:45:22 +01:00
parent cb819e77ee
commit 3c238fb5f7
8 changed files with 239 additions and 102 deletions
+37
View File
@@ -0,0 +1,37 @@
const db = require('../db');
async function eventRoutes(fastify) {
fastify.get('/events', async (request, reply) => {
const query = request.query || {};
if (!query.id) {
reply.code(400);
return { error: 'id is required' };
}
const id = Number.parseInt(query.id, 10);
if (!Number.isFinite(id)) {
reply.code(400);
return { error: 'id must be a number' };
}
const event = db.prepare(`SELECT id, title, created_at FROM events WHERE id = ?`).get(id);
if (!event) {
reply.code(404);
return { error: 'Event not found' };
}
const articles = db.prepare(`
SELECT id, title, description, content, url, normalized_title, source, pub_date, ingested_at
FROM articles
WHERE event_id = ?
AND content IS NOT NULL AND content != ''
AND is_index_page = 0
ORDER BY pub_date_effective DESC, id DESC
`).all(id);
return { ...event, articles };
});
}
module.exports = eventRoutes;