fix: order nearby schools by distance, not by how alike they are

Reported from staging: a Catholic primary showed six Catholic primaries, none
of them close enough to be a real option, and omitted the community school
down the road.

Three causes, compounding. Ranking put tier before distance, so a faith match
at 2.9 miles outranked a community school at 0.3. The ENOUGH=3 stopping rule —
added so a cap of six would not drag in weak distant matches — filled the row
from the best tier before it ever widened, which is what made every card
Catholic. And a 3-mile tier-1 radius is sane for a secondary and most of a city
for a primary, whose catchments are routinely under a mile.

The premise was backwards. For a parent, distance is a constraint and intake is
a preference; a school beyond a primary catchment is not a weaker option, it is
not an option. So distance now decides the order and nothing else does. The
hard filters are untouched — they were always where the defensibility lived.
Similarity survives as chips on the card: reported, so a reader applies their
own weighting, rather than ranked, so we apply ours for them.

Reach is capped per phase (primary 2, secondary 6, post-16 10) as a sanity
bound, not a target: ordering already handles density, so the cap only decides
what happens where an area is sparse. A primary with nothing inside two miles
now renders no section, which is the honest answer.

Deleted: the tier system, the stopping rule, the tier-dependent lede, the
`tier` field, the tier-3 fallback chip and its style. select_similar also stops
taking is_secondary — it reads the phase from the subject's own row, so no
caller can hand it one that disagrees with the data.

The heading is now "Other schools nearby". The hard filters still guarantee a
comparable set, but nothing ranks on likeness, so the heading no longer says it
does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
TudorandClaude Opus 5 committed 2026-09-22 13:06:32 +01:00
1 parent 151cf4bc80
commit 5c0ccc693d
11 files changed
+343 -278

No files matched your search

@@ -39,7 +39,6 @@
.shared { display: flex; flex-wrap: wrap; gap: 0.35rem; list-style: none; margin: 0 0 0.85rem; padding: 0; }
.chip { font-size: 0.72rem; line-height: 1.4; padding: 0.25rem 0.5rem; border-radius: 999px; background: var(--brand-bg); color: var(--brand); border: 1px solid transparent; }
.chipLoose { font-size: 0.72rem; line-height: 1.4; padding: 0.25rem 0.5rem; border-radius: 999px; background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.metric { margin-top: auto; padding-top: 0.8rem; border-top: 1px solid var(--border); }
/* No valence colour here, deliberately: green and terracotta mean "against the
@@ -1,12 +1,16 @@
/**
* SimilarSchoolsSection — nearby schools of the same phase and a comparable
* intake. Server component; only the carousel, the compare bar and the
* add-to-compare button are client-side.
* NearbySchoolsSection — the nearest eligible schools, closest first. Server
* component; only the carousel, the compare bar and the add-to-compare button
* are client-side.
*
* The section is allowed to say exactly what the backend matched and no more.
* The lede only claims a similar intake when no card came from tier 3, and a
* card's chips list what that school actually shares rather than a match it
* did not earn.
* "Other schools nearby", not "similar" ones: the order is distance and only
* distance. The hard filters upstream still guarantee the set is comparable —
* same phase, same selectivity, mainstream never beside special — but nothing
* here ranks by how alike two schools are, so the heading does not say it does.
*
* The chips report what a school shares, and may be absent entirely. That is
* information for the reader to weigh, not a verdict this section has already
* reached on their behalf.
*
* There is deliberately no "how these are chosen" panel: the method is already
* visible in the lede, the chips and the distances. The single caption line is
@@ -78,25 +82,20 @@ export function SimilarSchoolsSection({
// One card matched on phase alone, so the section may not claim the set
// shares an intake with this school.
const loosest = Math.max(...schools.map((s) => s.tier));
const metricKey = schools[0].metric_key;
const noun = nearbyNoun(phase);
return (
<Section id="similar">
<Section id="nearby">
<SimilarSchoolsCarousel
count={schools.length}
labelledBy="similar-schools-heading"
labelledBy="nearby-schools-heading"
header={
<div>
<h2 id="similar-schools-heading" className={styles.heading}>
Similar schools nearby
<h2 id="nearby-schools-heading" className={styles.heading}>
Other schools nearby
</h2>
<p className={styles.lede}>
{loosest >= 3
? `Other ${noun} near ${schoolName}.`
: `Other ${noun} near ${schoolName}, with a similar intake.`}
</p>
<p className={styles.lede}>{`Other ${noun} near ${schoolName}.`}</p>
</div>
}
>
@@ -113,13 +112,13 @@ export function SimilarSchoolsSection({
.filter(Boolean)
.join(' · ')}
</p>
<ul className={styles.shared}>
{school.shared.map((label) => (
<li key={label} className={school.tier >= 3 ? styles.chipLoose : styles.chip}>
{label}
</li>
))}
</ul>
{school.shared.length > 0 && (
<ul className={styles.shared}>
{school.shared.map((label) => (
<li key={label} className={styles.chip}>{label}</li>
))}
</ul>
)}
<div className={styles.metric}>
<p
className={