The location gate rejects on evidence only: a place gate is empty for a role with no place the gazetteer resolved, an any group whose country and place members are all empty passes whatever remote says, and a role place that holds one of a country or place gate's places (Øresund, Sweden, Europe) meets it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
1127d06f03
commit
3388b97cf4
4 files changed
+150
-22
No files matched your search
+31
-12
@@ -289,14 +289,22 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
|
||||
`params` belong to `match`; `empty` takes none.
|
||||
|
||||
`country` and `place` match over the gazetteer, as the feed's Place
|
||||
filter does (`_places_sql`): a country gate is met by a role whose
|
||||
`country` is one of its codes or that has a place in one of them, so
|
||||
`DK` is met by `Copenhagen; London`. Its column is empty only when the
|
||||
role has neither. A `require` gate on country reads a remote role whose
|
||||
filter does (`_places_sql`), and also on a role place that holds one of
|
||||
the gate's places (`wider`): a country gate is met by a role whose
|
||||
`country` is one of its codes or that has a place in or around one of
|
||||
them, so `DK` is met by `Copenhagen; London`, and by Øresund or Europe
|
||||
alone, which are no evidence the role is outside Denmark; a town in
|
||||
Germany is. Its column is empty only when the role has neither a country
|
||||
nor a resolved place. A `require` gate on country reads a remote role whose
|
||||
area is stated through the area alone, as the remote chips do
|
||||
(`Gazetteer.overlap`): "Home Based - Worldwide" and "Germany (Remote)"
|
||||
meet Europe, "Remote US" does not, and neither is empty. A place gate's
|
||||
value is a place token, bare text a `place:`.
|
||||
value is a place token, bare text a `place:`. Its column is empty when
|
||||
the role has no place the gazetteer resolved, as "Storkøbenhavn" or
|
||||
"Headquarters" are not: that is no evidence the role is elsewhere. Such
|
||||
a role can still match, by its country or by whole words of its line
|
||||
for a town the gazetteer does not know, so a place gate's `match` is
|
||||
tested before its `empty` (`Store.score_candidates`).
|
||||
|
||||
`remote_from` takes place tokens without their `remote:` (`country:DK`,
|
||||
`anywhere`) and matches as the remote chips do. It is empty for a role
|
||||
@@ -314,7 +322,8 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
|
||||
return f"(r.remote = '' OR (r.remote = 'remote' AND NOT {_HAS_AREA}))", match, params
|
||||
if gate.field == "country":
|
||||
tokens = [f"country:{v}" for v in values]
|
||||
match, params = _places_sql(tokens, gaz, table="r", codes=[v.upper() for v in values])
|
||||
match, params = _places_sql(tokens, gaz, table="r", codes=[v.upper() for v in values],
|
||||
wider=True)
|
||||
empty = f"(r.country = '' AND {_unplaced(gaz)})"
|
||||
if gate.mode != "require":
|
||||
return empty, match, params
|
||||
@@ -323,8 +332,8 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
|
||||
return (f"({empty} AND NOT {_HAS_AREA})",
|
||||
f"(CASE WHEN {_HAS_AREA} THEN {area} ELSE {match} END)", [*more, *params])
|
||||
if gate.field == "place":
|
||||
match, params = _places_sql(values, gaz, table="r")
|
||||
return "r.place = ''", match, params
|
||||
match, params = _places_sql(values, gaz, table="r", wider=True)
|
||||
return _unplaced(gaz), match, params
|
||||
if gate.field == "title":
|
||||
# Whole words of the folded title: " account executive " inside
|
||||
# " enterprise account executive uk ". A fold drops `%` and `_`, so a
|
||||
@@ -344,13 +353,19 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
|
||||
|
||||
|
||||
def _places_sql(tokens: Sequence[str], gaz: places.Gazetteer, *, table: str = "roles",
|
||||
codes: Sequence[str] = (), scope: Sequence[Gate] = ()) -> tuple[str, list[Any]]:
|
||||
codes: Sequence[str] = (), scope: Sequence[Gate] = (),
|
||||
wider: bool = False) -> tuple[str, list[Any]]:
|
||||
"""Any of the place tokens over `table`, as a join over the gazetteer: a
|
||||
role with a place under one of the places the tokens name (`country:DK`
|
||||
every place in Denmark, `region:skane` every town in Skåne, `place:malmo`
|
||||
Malmö by any spelling), or whose `country` is one of their countries (a
|
||||
role whose board gave a country and no place). `codes` are more values of
|
||||
`country` to accept. A `place:` token the gazetteer does not know is
|
||||
`country` to accept. `wider` also takes a role place that holds one of
|
||||
them (`Gazetteer.overlap`): Øresund, Europe or Anywhere meet
|
||||
`country:DK`, as the fetch gate reads them (`_gate_sql`); the feed's
|
||||
Place filter leaves it off. The `country` column is not widened, as
|
||||
Sweden would then meet Malmö for a role in Stockholm. A `place:` token
|
||||
the gazetteer does not know is
|
||||
matched on whole words of the role's folded line (`places.match_sql`),
|
||||
so a town nobody has entered yet is still found.
|
||||
|
||||
@@ -381,7 +396,7 @@ def _places_sql(tokens: Sequence[str], gaz: places.Gazetteer, *, table: str = "r
|
||||
params += values
|
||||
continue
|
||||
under = gaz.under(named)
|
||||
ids |= under
|
||||
ids |= gaz.overlap(named) if wider else under
|
||||
found |= gaz.codes(under)
|
||||
if ids:
|
||||
clauses.insert(0, f"{table}.uid IN (SELECT uid FROM role_places "
|
||||
@@ -2317,7 +2332,11 @@ class Store:
|
||||
empty, match, values = _gate_sql(part, gaz)
|
||||
whens.append(f"WHEN {match} THEN {k}")
|
||||
params += values
|
||||
columns.append(f"CASE WHEN {empty} THEN -1 {' '.join(whens)} ELSE 0 END AS g{n}")
|
||||
# A place gate's match goes first: an unresolved place can still
|
||||
# meet one of its values (`_gate_sql`).
|
||||
case = (f"{' '.join(whens)} WHEN {empty} THEN -1" if gate.field == "place"
|
||||
else f"WHEN {empty} THEN -1 {' '.join(whens)}")
|
||||
columns.append(f"CASE {case} ELSE 0 END AS g{n}")
|
||||
select = ", ".join(["r.uid", "r.posted_at",
|
||||
"COALESCE(ac.affinity, 0) AS affinity",
|
||||
"COALESCE(c.all_countries, 0) AS all_countries",
|
||||
|
||||
Reference in new issue
Block a user