Match places with a registered function in the plan, since LIKE took 400 ms a region

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-29 22:02:07 +02:00
1 parent 4ca362ef83
commit af0c4ae5b3
1 file changed
+9 -4
+9 -4
View File
@@ -37,7 +37,9 @@ The Place filter is a substring of `place`, so `Denmark` misses `København K` a
**A filter pushes a history entry, the search box and typing replace it.** This reverses the rule in `roles.js` that a filter replaces. `popstate` reads the address into the filter and reloads. Agent and order are not filters and replace.
**A place is matched on whole folded words.** `roles.place_fold` holds `places.fold(place)`: casefolded, marks stripped, `ø` to `o`, `æ` to `ae`, `å` to `a`, punctuation to spaces. A match is `' ' || place_fold || ' ' LIKE '% lund %'`, so `Lund` no longer finds `Billund`. The `place` gate uses the same matcher.
**A place is matched on whole folded words.** `roles.place_fold` holds `places.fold(place)`: casefolded, marks stripped, `ø` to `o`, `æ` to `ae`, `å` to `a`, punctuation to spaces. `Lund` is the word `lund`, so it no longer finds `Billund`. The `place` gate uses the same matcher.
**The match is a Python function registered on the connection, not `LIKE`.** A region is up to 161 phrases. As `LIKE` clauses over 34,538 roles `region:oresund` took 400 ms, `region:hovedstaden` 250 ms, and the feed asks twice, for the count and the page. `places.matches` behind `place_match(place_fold, country, ?)` took 14 ms cold and 5 ms warm.
**A place filter is a token.** `country:DK` matches `country = 'DK'`, or a role whose country is empty or `EU` and whose `place_fold` has a name of that country. `region:skane` matches any town or name of the region in `app/places.py`. `place:malmo` matches the folded words and the aliases of that town (`copenhagen`, `kobenhavn`, `kopenhamn`). Several tokens are joined by OR. A `place` gate value accepts the same tokens, a bare value is read as `place:`.
@@ -54,12 +56,15 @@ Every package builds against this, so waves can run before the one below has mer
```python
def fold(text: str) -> str # "Skåne län" -> "skane lan", "København K" -> "kobenhavn k"
def parse(token: str) -> Token # "country:DK", "region:skane", "place:malmo"; bare text -> place
def known(token: str) -> bool # False for region:atlantis, country:ZZ, an empty value
def matches(place_fold: str, country: str, token: str) -> bool
def register(conn: sqlite3.Connection) -> None # place_match(place_fold, country, token)
def match_sql(token: str, *, place: str = "place_fold", country: str = "country") -> tuple[str, list]
def suggest(q: str, places: Iterable[tuple[str, str, int]], limit: int = 12) -> list[Suggestion]
REGIONS: dict[str, Region] # key -> label, names, towns
```
`Token` has `kind`, `value`, `label`. `Suggestion` has `token`, `label`, `kind` (`country`, `region`, `place`) and `count`. `places` is `(place, country, open roles)`. A place suggestion is a town: the first comma part of each `;` part of `place`, grouped by its fold, labelled by its commonest spelling. `q` matches a word prefix of the fold of a label, name or alias. Countries come first, then regions, then towns by count. Regions to start with: Skåne, Capital Region of Denmark, Zealand, Øresund (the two capital regions), Jutland, Funen.
`match_sql` answers `place_match(<place>, <country>, ?)` with the token as its parameter, so every connection that runs it has called `register`. `Token` has `kind`, `value`, `label`. `Suggestion` has `token`, `label`, `kind` (`country`, `region`, `place`) and `count`. `places` is `(place, country, open roles)`. A place suggestion is a town: the first comma part of each `;` part of `place`, grouped by its fold, labelled by its commonest spelling. `q` matches a word prefix of the fold of a label, name or alias. Countries come first, then regions, then towns by count. Regions to start with: Skåne, Capital Region of Denmark, Zealand, Øresund (the two capital regions), Jutland, Funen.
### `app/seniority.py` (package B)
@@ -98,7 +103,7 @@ New parameters, the old `company` and `place` substrings stay for links from oth
window.chipInput(root, { suggest, onChange, placeholder, label }) -> { values(), set(items), clear() }
```
`root` is an empty element. `suggest(q)` resolves to `[{value, label, hint}]`. An item is `{value, label}`. A pick becomes a chip with a remove button; Enter picks the first suggestion, arrows move, Escape shuts the list, Backspace in an empty field removes the last chip. Text that matches no suggestion becomes no chip. `onChange(items)` runs after each add or remove.
`root` is an empty element. `suggest(q)` resolves to `[{value, label, hint}]`. An item is `{value, label}`. A pick becomes a chip with a remove button; Enter picks the first suggestion, arrows move, Escape shuts the list, Backspace in an empty field removes the last chip. Text that matches no suggestion becomes no chip. `onChange(items)` runs after each add or remove by the person; `set` and `clear` are the page's own and do not call it. The tests run with `node --test tests/js/*.test.mjs`.
## Work packages
@@ -124,7 +129,7 @@ F in detail: the company name in a feed row and in the reader is a link to `/?co
|---|---|---|
| E, storage and API | Opus | `app/storage/store.py`, `app/storage/schema.py`, `app/web/api.py`, `app/models.py`, `plugins/ats.py`, `tests/test_storage.py`, `tests/test_web.py` |
Migration 17 adds `roles.place_fold` with an index-free backfill, and fills `seniority` from the title where it is empty. `upsert_role` writes both. `_gate_sql` uses `places.match_sql`.
Migration 17 adds `roles.place_fold` and fills it, and fills `seniority` from the title where it is empty. `upsert_role` writes both. `Store._connect` calls `places.register`. `_gate_sql` uses `places.match_sql`.
### Wave 3, after D, E and F are merged