fix(viewer): Tier-0 search applies tier-1's match rule through one shared function

Merged
LO
19d ago
+401-201

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:

  1. 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.
  2. A candidate scores by the substring ladder, else TOKEN_MATCH when every query token hit.
  3. 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 tsc clean; module-size check clean.

Cost (Node, one Tier-0 scan)

rowsquerymainthis PR
200ksingle word142–169 ms104–132 ms
200kmulti-word117–135 ms122–172 ms
2Msingle word1.5–1.7 s1.1–1.6 s
2Mmulti-word1.4–1.5 s1.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