---
estimated_steps: 4
estimated_files: 4
skills_used: []
---

# T01: Backend sort params on search, subtopic, and techniques endpoints

1. Add `sort` query param to search endpoint in `backend/routers/search.py` — pass to `SearchService.search()`. Support values: `relevance` (default, by score desc), `newest` (created_at desc), `oldest` (created_at asc), `alpha` (title asc), `creator` (creator_name asc).
2. In `SearchService.search()` and `keyword_search()`, apply sort ORDER BY to keyword results. For semantic results from Qdrant, sort the enriched list in Python (Qdrant returns by score already; for other sorts, re-sort after enrichment).
3. Add `sort` query param to subtopic endpoint in `backend/routers/topics.py` — `get_subtopic_techniques()`. Same sort options minus 'relevance'. Default: 'alpha' (current behavior).
4. Techniques list endpoint already has `sort` param — extend it with `oldest`, `alpha`, `creator` options (currently only `recent` and `random`).

## Inputs

- `backend/routers/search.py`
- `backend/routers/topics.py`
- `backend/routers/techniques.py`

## Expected Output

- `backend/routers/search.py (sort param)`
- `backend/routers/topics.py (sort param on subtopic)`
- `backend/routers/techniques.py (extended sort options)`
- `backend/search_service.py (sort logic)`

## Verification

curl tests: `curl 'http://localhost:8001/api/v1/search?q=snare&sort=newest'` returns results in created_at desc order. `curl 'http://localhost:8001/api/v1/topics/sound-design/bass?sort=oldest'` returns oldest first.
