add event clustering feature to group articles by similarity and time proximity
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user