Files
linkedstorm/app/api/routes/search.py
T
pluto 59014f6fe7 feat: API routes — speakers, rooms, search, RAG
Full implementations replacing stubs: speakers CRUD with utterance count,
rooms list + mute/unmute via pipeline, FTS5-based search, RAG /ask and
/summary endpoints. 15 route tests (8 new) all passing; 35 total.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 10:46:24 -05:00

27 lines
809 B
Python

import sqlite3
from typing import Optional
from fastapi import APIRouter
def make_router(settings, db_factory):
router = APIRouter(prefix="/api")
@router.get("/search")
def search(q: str, date: Optional[str] = None):
if not q.strip():
return []
db: sqlite3.Connection = db_factory()
rows = db.execute("""
SELECT u.*, r.name as room_name, s.name as speaker_name
FROM utterances_fts fts
JOIN utterances u ON u.id = fts.rowid
JOIN rooms r ON u.room_id = r.id
LEFT JOIN speakers s ON u.speaker_id = s.id
WHERE utterances_fts MATCH ?
ORDER BY u.start_time DESC
LIMIT 100
""", (q.strip(),)).fetchall()
return [dict(r) for r in rows]
return router