A teammate’s pull request adds a Fresh mode to the docs search: pages edited in the last 48 hours come first, then the rest, each group by relevance. It also adds rankForRequest, which the search page and the palette call once per request with the reader’s mode, the editors’ pins and the app’s clock. QA reports that Fresh orders the same pages differently from one run to the next, and that pinned pages and deprecated pages behave differently under Fresh than under every other mode. You are reviewing the pull request before it merges.
A ranking that reshuffles on refresh looks broken, and any test that pins its order fails at random. Under Fresh, editors’ pins stop working and deprecated pages rise again, the two rules the last two levels put in place.
Reproduce
With a clock that moves on a day each time it is read (time passing during a sort, exaggerated), Fresh over api (score 90, edited 35 hours ago) and release (65, edited 30 hours ago) should give api, release: both are fresh. Today it gives release, api.
Acceptance criteria
- Under Fresh, a page is fresh if it was edited at most 48 hours before the request; fresh pages come first, each group by relevance.
- Every comparison in one request sees the same time, and the next request sees its own, later time.
- Under Fresh, as under every mode, pinned results come first, deprecated pages sink and ties settle by ID.
- Relevance and Recent are unchanged, and an unknown mode is rejected.
Notes
- The checker makes one fake clock per case, starting at hour 1000 and moving on 24 hours every time it is read, and calls rankForRequest (RankForRequest in Go, rank_for_request in Rust) once per request. It prints the ranked IDs, requests joined by “ | ”, or rejected.
- Keep rankForRequest’s signature, the SearchResult type, pinnedFirst and rankResults; the checker calls rankForRequest only, so the rest of the shape is your call.
- Rust: from Rust 1.81, sort_by may panic when the comparison is not a total order, and a comparison that changes its mind mid-sort is not one. The lab runs Rust 1.63, which returns some order instead.