Skip to content

fix(cli): rank exact keyword phrase matches above token-sum scores - #5289

Merged
cixzhang merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/cli-search-exact-keyword-phrase-ranking
Sep 3, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/cli-search-exact-keyword-phrase-ranking

Conversation

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor

Fixes #5239 (the first, cheapest of the issue's suggested fixes: "rank exact whole-phrase keyword matches above partial name-token matches").

Problem

astryx search "table of contents" never surfaced Outline, even though Outline.doc.mjs declares 'table of contents' verbatim as a keyword. Traced precisely: scoreCandidate correctly computes an exact-keyword score of 90 for Outline against that query. The bug is that scoreQuery's multi-word token-sum path (which scores "table" and "contents" as separate tokens against every OTHER candidate) regularly produces scores above 90, since dozens of Table-related templates and components each match one of those two common words independently. With the default --limit 20, roughly 53 other candidates outscored Outline's exact match, pushing it out of the results entirely.

Same root cause for "heading navigation" against Outline's 'heading navigation' keyword.

Fix

When the full, untokenized query exactly matches a candidate's name or a declared keyword verbatim (scoreCandidate score 90 or 100, the only two outcomes at or above that mark), promote it to a reserved top tier (score + 100) that's safely above the token-sum path's mathematical ceiling (~151: 100 avg + 36 matched-count bonus + 15 coverage bonus). This is a targeted priority rule, not a rebalancing of the existing 0-100 scale, so it can't regress any query that doesn't have a genuine exact whole-phrase match.

Scope (intentionally narrow)

This addresses exactly suggestion #1 from the issue, "no metadata changes anywhere." The issue's second, narrower bug ("on this page" returning zero results because a query consisting entirely of stopwords has no fallback) is a separate, vaguer problem the issue itself frames as needing more judgment ("relax to a ranked OR... though it is a band-aid"), so I left it out of this PR rather than bundle a riskier, less-verified change into the same fix. Happy to take that on separately if useful.

Verification

Ran every query from the issue's own reproduction table against the real component registry, before and after:

query before after
table of contents absent Outline, rank 1
heading navigation absent Outline, rank 1
copy button (already worked) useClipboard, rank 1 useClipboard, rank 1 (unaffected)
markdown renderer (already worked) Markdown, rank 1 Markdown, rank 1 (unaffected)
mobile drawer (already worked) useAppShellMobile, rank 1 useAppShellMobile, rank 1 (unaffected)
data visualization (already worked) useTheme, rank 1 useTheme, rank 1 (unaffected)
zzzzqqqx (nonsense) 0 results 0 results (unaffected, confirms no over-triggering)

Added two regression tests (a new "exact keyword phrase outranks incidental token matches" describe block, matching the file's existing em-dash naming convention for its own describe blocks) asserting Outline ranks first for both previously-failing queries, plus a nonsense-query sanity check. Both fail against the pre-fix implementation (verified by temporarily reverting just the implementation file) and pass with the fix.

Full search and build API test suites pass (19 tests; build's own ranking floors in kit.mjs are all >= threshold checks, so this monotonic score increase for exact matches can only make build more confident about a genuine keyword match, never less). Lint and typecheck (tsconfig.strict.json) show no new issues; a pre-existing, unrelated failure in component.test.mjs (a case-sensitivity assertion, confirmed failing identically on a clean baseline with my changes fully reverted) is untouched by this diff.

A query that exactly matches a candidate's declared keyword verbatim
(e.g. "table of contents" against Outline's own literal keyword)
could still fail to surface it at all, if enough other candidates
each happened to match one of the query's individual words
separately. The multi-word token-sum path sums per-word scores plus
a coverage bonus, and that sum regularly exceeded the fixed 90-point
ceiling for an exact keyword match, since dozens of Table-related
templates each matched "table" and "contents" independently.

An exact whole-phrase match against a candidate's name or a declared
keyword is now promoted to a reserved top tier (its score plus 100),
safely above the token-sum path's mathematical ceiling (~151), so it
always outranks a candidate that only coincidentally contains
several of the query's individual words. Single-word queries and
queries that don't exactly match a name/keyword are unaffected.

Verified against the issue's own repro table: "table of contents"
and "heading navigation" now surface Outline first, matching the
five already-working examples the issue cited (copy button, markdown
renderer, mobile drawer, data visualization), which are unaffected.
A nonsense query still returns nothing.
@vercel

vercel Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 21, 2026 9:09am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 21, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 21, 2026
No established em-dash convention in this file's prose comments
(only in its describe-block titles), unlike search.mjs itself.
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 21, 2026
@nynexman4464

Copy link
Copy Markdown
Contributor

Thanks for looking into this. I don't think #5239 was fully specified enough to be ready for implementation. Before changing the ranking, we'd want regression coverage showing that existing good searches don't get worse, and I'm not sure we have a solid search-quality benchmark yet. I wouldn't spend any more of your tokens on this for now.

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builders can find Outline by its declared phrases. Both regressions move from absent to first; focused suites pass. mobile drawer also improves from fifth to first.

[Reviewed by Robohands]

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Sep 3, 2026
@cixzhang
cixzhang merged commit f44af81 into meta:main Sep 3, 2026
26 of 27 checks passed
josephfarina pushed a commit that referenced this pull request Sep 4, 2026
…5289)

* fix(cli): rank exact keyword phrase matches above token-sum scores

A query that exactly matches a candidate's declared keyword verbatim
(e.g. "table of contents" against Outline's own literal keyword)
could still fail to surface it at all, if enough other candidates
each happened to match one of the query's individual words
separately. The multi-word token-sum path sums per-word scores plus
a coverage bonus, and that sum regularly exceeded the fixed 90-point
ceiling for an exact keyword match, since dozens of Table-related
templates each matched "table" and "contents" independently.

An exact whole-phrase match against a candidate's name or a declared
keyword is now promoted to a reserved top tier (its score plus 100),
safely above the token-sum path's mathematical ceiling (~151), so it
always outranks a candidate that only coincidentally contains
several of the query's individual words. Single-word queries and
queries that don't exactly match a name/keyword are unaffected.

Verified against the issue's own repro table: "table of contents"
and "heading navigation" now surface Outline first, matching the
five already-working examples the issue cited (copy button, markdown
renderer, mobile drawer, data visualization), which are unaffected.
A nonsense query still returns nothing.

* fix: remove em dash from test comment

No established em-dash convention in this file's prose comments
(only in its describe-block titles), unlike search.mjs itself.
josephfarina added a commit that referenced this pull request Sep 4, 2026
scoreQuery's signature says every hit carries matched/total, and #5320 added
them, but the promote tier #5289 added returns before that. tsc catches it, so
sync:api-types fails and `pnpm build` is red on main.

A whole-phrase hit answered the whole query by definition, which is what asFull
already means - so reuse it and override the score.

This branch was successfully deployed

1 active deployment
Preview — f968d7c2 Deployed Aug 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] astryx search: Outline is unreachable by its own table of contents keyword

3 participants