UI/UX: - Bill detail page tab UI (Analysis / Timeline / Votes / Notes) - Topic tag pills on bill detail and listing pages — filtered to known topics, clickable, properly labelled via shared lib/topics.ts - Notes panel always-open in Notes tab; sign-in prompt for guests - Collapsible sidebar with icon-only mode and localStorage persistence - Bills page defaults to has-text filter enabled - Follow mode dropdown transparency fix - Favicon (Landmark icon, blue background) Security: - Fernet encryption for ntfy passwords at rest (app/core/crypto.py) - Separate ENCRYPTION_SECRET_KEY env var; falls back to JWT derivation - ntfy_password no longer returned in GET response — replaced with ntfy_password_set: bool; NotificationSettingsUpdate type for writes - JWT_SECRET_KEY fail-fast on startup if using default placeholder - get_optional_user catches (JWTError, ValueError) only, not Exception Bug fixes & code quality: - Dashboard N+1 topic query replaced with single OR query - notification_utils.py topic follower N+1 replaced with batch query - Note query in bill detail page gated on token (enabled: !!token) - search.py max_length=500 guard against oversized queries - CollectionCreate.validate_name wired up with @field_validator - LLM_RATE_LIMIT_RPM default raised from 10 to 50 Authored by: Jack Levy
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy import func, or_, select, text
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database import get_db
|
|
from app.models import Bill, Member
|
|
from app.schemas.schemas import BillSchema, MemberSchema
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("")
|
|
async def search(
|
|
q: str = Query(..., min_length=2, max_length=500),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
# Bill ID direct match
|
|
id_results = await db.execute(
|
|
select(Bill).where(Bill.bill_id.ilike(f"%{q}%")).limit(20)
|
|
)
|
|
id_bills = id_results.scalars().all()
|
|
|
|
# Full-text search on title/content via tsvector
|
|
fts_results = await db.execute(
|
|
select(Bill)
|
|
.where(text("search_vector @@ plainto_tsquery('english', :q)"))
|
|
.order_by(text("ts_rank(search_vector, plainto_tsquery('english', :q)) DESC"))
|
|
.limit(20)
|
|
.params(q=q)
|
|
)
|
|
fts_bills = fts_results.scalars().all()
|
|
|
|
# Merge, dedup, preserve order (ID matches first)
|
|
seen = set()
|
|
bills = []
|
|
for b in id_bills + fts_bills:
|
|
if b.bill_id not in seen:
|
|
seen.add(b.bill_id)
|
|
bills.append(b)
|
|
|
|
# Fuzzy member search — matches "Last, First" and "First Last"
|
|
first_last = func.concat(
|
|
func.split_part(Member.name, ", ", 2), " ",
|
|
func.split_part(Member.name, ", ", 1),
|
|
)
|
|
member_results = await db.execute(
|
|
select(Member)
|
|
.where(or_(
|
|
Member.name.ilike(f"%{q}%"),
|
|
first_last.ilike(f"%{q}%"),
|
|
))
|
|
.order_by(Member.last_name)
|
|
.limit(10)
|
|
)
|
|
members = member_results.scalars().all()
|
|
|
|
return {
|
|
"bills": [BillSchema.model_validate(b) for b in bills],
|
|
"members": [MemberSchema.model_validate(m) for m in members],
|
|
}
|