fix(viewer): Tier-0 search applies tier-1's match rule through one shared function
Landing order: this PR must land before #9782. #9782 defers the tier-1 build until after load, so searches at interactive answer from Tier-0, and this PR makes Tier-0's rows identical to tier-1's.
Summary
A search answers from the Tier-0 scan until a model's tier-1 index is built, then from tier-1. The two tiers applied different rules, so results could change under the user right after a model became interactive. #9782 defers the tier-1 build, which makes that window longer.
Tier-1's rule, unchanged:
- A row is a candidate when a query token (lower-cased, split on
[\s\-_./:], one-letter non-digit tokens dropped) is a prefix of one of its name/type/description/object-type tokens. - A candidate scores by the substring ladder, else
TOKEN_MATCHwhen every query token hit. - Only a model with no candidate is swept by substring, and only for a needle under 3 characters or containing a separator.
Tier-0 scored includes(needle) on every row, plus (after this PR's first push) a token fallback. They disagreed on:
- multi-word queries ("Room A", "wall basement" vs "Basement Wall");
- mid-word substrings: "oom", "ath", "asement" and "all" returned rows from Tier-0 only.
The fix. The rule lives in one place, search-match.ts, and both tiers call it: prepareSearchQuery, SCORE, substringMatch, rowTokenHits, resolveModelMatches.
- Tier-1 still finds candidates through its postings.
- Tier-0 finds them in one pass over the rows with
rowTokenHits. It reuses one row view and per-table lower-cased strings, and rejects a row without tokenizing it when no query token occurs in its text. - Tier-1's results are unchanged.
Tests (tier-parity.test.ts)
- Corpus: 44 queries over two models (mid-word, prefix, multi-word, one-letter words, separators, GUID, ß/umlauts, İ, CJK, descriptions, object types).
- Generated: 400 queries (substrings and word permutations of the stores' own text).
- Assertion: identical rows, scores, match fields and order. Both fail on the previous head ("Room A", "oom").
- Search suites: 341 pass. Viewer
tscclean; module-size check clean.
Cost (Node, one Tier-0 scan)
| rows | query | main | this PR |
|---|---|---|---|
| 200k | single word | 142–169 ms | 104–132 ms |
| 200k | multi-word | 117–135 ms | 122–172 ms |
| 2M | single word | 1.5–1.7 s | 1.1–1.6 s |
| 2M | multi-word | 1.4–1.5 s | 1.5–2.0 s |
Main's Tier-0 scan already blocks the main thread for about 1.4 s per keystroke on a 2M-row model. A bounded, yielding scan needs the search UI's synchronous results memo to become async, so it will be a separate follow-up PR.
🤖 Generated with Claude Code