Closer to Home: gate "Near you" on high/medium confidence (both modes)
Codex polish before deploy: anything elevated as Near you / Close to home must have geo_confidence in (high, medium) — the feature's promise is relevance. Country-only mode now gates "near" too; since it has no "country" tier, the "world" scope is widened to absorb low-confidence home-country stories so they surface there instead of vanishing between tiers (the same edge-case class, fixed). State mode unchanged. 364 tests green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+17
-3
@@ -171,13 +171,17 @@ def feed(
|
||||
# shaky location). Untagged articles have no places, so they land in 'world' — never
|
||||
# lost while the backfill is still running.
|
||||
if geo_scope == "near":
|
||||
# Anything elevated as "Near you" / "Close to home" requires high/medium geo
|
||||
# confidence — the feature's promise is relevance, so don't surface shaky locals.
|
||||
if home_state and home_country:
|
||||
clauses.append(
|
||||
"g.confidence IN ('high','medium') AND EXISTS (SELECT 1 FROM article_places p "
|
||||
"WHERE p.article_id = a.id AND p.country_code = ? AND p.state_code = ?)")
|
||||
params.extend([home_country, home_state])
|
||||
elif home_country:
|
||||
clauses.append("EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
|
||||
clauses.append(
|
||||
"g.confidence IN ('high','medium') AND EXISTS (SELECT 1 FROM article_places p "
|
||||
"WHERE p.article_id = a.id AND p.country_code = ?)")
|
||||
params.append(home_country)
|
||||
elif geo_scope == "country" and home_country:
|
||||
clauses.append("EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
|
||||
@@ -191,8 +195,18 @@ def feed(
|
||||
"WHERE p2.article_id = a.id AND p2.country_code = ? AND p2.state_code = ?))")
|
||||
params.extend([home_country, home_state])
|
||||
elif geo_scope == "world" and home_country:
|
||||
clauses.append("NOT EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
|
||||
params.append(home_country)
|
||||
if home_state:
|
||||
# State mode: the "country" tier catches all home-country stories (incl.
|
||||
# low-confidence ones), so world is simply everything outside your country.
|
||||
clauses.append("NOT EXISTS (SELECT 1 FROM article_places p WHERE p.article_id = a.id AND p.country_code = ?)")
|
||||
params.append(home_country)
|
||||
else:
|
||||
# Country-only mode has no "country" tier, so a LOW-confidence home-country
|
||||
# story isn't "near" and must land here rather than vanish between tiers.
|
||||
clauses.append(
|
||||
"NOT (g.confidence IN ('high','medium') AND EXISTS (SELECT 1 FROM article_places p "
|
||||
"WHERE p.article_id = a.id AND p.country_code = ?))")
|
||||
params.append(home_country)
|
||||
|
||||
where = "WHERE " + " AND ".join(clauses)
|
||||
params.extend([limit, offset])
|
||||
|
||||
Reference in New Issue
Block a user