smarter context assembly implementation
This commit is contained in:
@@ -64,4 +64,14 @@ function getEntityNeighbors(entityIds) {
|
||||
return { nodes, edges };
|
||||
}
|
||||
|
||||
module.exports = { getNeighborhood, getEntityNeighbors };
|
||||
// Returns episode IDs linked to any of the given entity IDs via entity_episodes
|
||||
function getEpisodeIdsByEntities(entityIds) {
|
||||
if (!entityIds.length) return [];
|
||||
const db = getDB();
|
||||
const ph = entityIds.map(() => '?').join(',');
|
||||
return db.prepare(
|
||||
`SELECT DISTINCT episode_id FROM entity_episodes WHERE entity_id IN (${ph})`
|
||||
).all(...entityIds).map(r => r.episode_id);
|
||||
}
|
||||
|
||||
module.exports = { getNeighborhood, getEntityNeighbors, getEpisodeIdsByEntities };
|
||||
|
||||
@@ -251,6 +251,14 @@ app.post('/graph/neighbors', (req, res) => {
|
||||
res.json(graph.getEntityNeighbors(entityIds.map(Number)));
|
||||
});
|
||||
|
||||
app.post('/episodes/by-entities', (req, res) => {
|
||||
const { entityIds } = req.body;
|
||||
if (!Array.isArray(entityIds) || entityIds.length === 0) {
|
||||
return res.status(400).json({ error: 'entityIds array is required' });
|
||||
}
|
||||
res.json({ episodeIds: graph.getEpisodeIdsByEntities(entityIds.map(Number)) });
|
||||
});
|
||||
|
||||
/*********************************** */
|
||||
/********** Project Routes ********** */
|
||||
/*********************************** */
|
||||
|
||||
Reference in New Issue
Block a user