Geo Stage 4 (data layer): geo on feed responses + home-scope query filters
Foundation for "Closer to Home" (server-side, Codex-approved). No behavior change
yet — geo_scope defaults None, so the default/edge-cached feed is identical.
- queries.feed now returns each article's geo (breadth, confidence, and ISO-coded
places) via a LEFT JOIN + places subquery. Article.from_row parses geo_places
into [{country, state}]. Brief query doesn't select geo, so the Brief stays bare.
- queries.feed gains home-scope filters (home_country/home_state/geo_scope =
near|country|world): STATE match only counts on high/medium geo confidence;
untagged articles fall to 'world' so nothing is lost during backfill.
Next: API composition (home param + near/country/world sectioning with soft/blended
headers + a next_offset pagination model) and the Home picker UI. 360 tests green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -322,11 +322,26 @@ class Article(BaseModel):
|
||||
paywalled: bool = False
|
||||
tags: list[str] = []
|
||||
summary: str | None = None # our own cached summary (present on the brief)
|
||||
# Subject geography (present on feed rows; absent/empty on the brief). breadth is
|
||||
# locality|regional|national|multinational|global|unknown; places are ISO codes.
|
||||
geo_breadth: str | None = None
|
||||
geo_confidence: str | None = None
|
||||
geo_places: list[dict] = [] # e.g. [{"country": "US", "state": "NY"}, {"country": "GB", "state": None}]
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: dict) -> "Article":
|
||||
raw_tags = row.get("tags")
|
||||
places = []
|
||||
for tok in (row.get("geo_places") or "").split(","):
|
||||
tok = tok.strip()
|
||||
if not tok:
|
||||
continue
|
||||
cc, _, sc = tok.partition("-")
|
||||
places.append({"country": cc, "state": sc or None})
|
||||
return cls(
|
||||
geo_breadth=row.get("geo_breadth"),
|
||||
geo_confidence=row.get("geo_confidence"),
|
||||
geo_places=places,
|
||||
summary=row.get("summary"),
|
||||
id=row["id"],
|
||||
title=row["title"],
|
||||
|
||||
Reference in New Issue
Block a user