"""What the /articles and /search rollup now returns, top 3."""
from app.database import SessionLocal
from app.services.search_service import article_ids_with_sections
from app.models.article import Article

db = SessionLocal()
titles = dict(db.query(Article.id, Article.title).all())
for q in ["supraglottoplasty", "griseofulvin",
          "surgery for infant stridor that fails to improve",
          "endoscopic division of the aryepiglottic folds",
          "antifungal taken by mouth for weeks with fatty food"]:
    ids, by_article = article_ids_with_sections(db, q, limit=20)
    top = [titles.get(i) for i in ids[:3]]
    secs = [s.title for s in by_article.get(ids[0], [])[:2]] if ids else []
    print(f"  {q!r}\n      -> {top}   sections cited: {secs}")
db.close()
