Skip to content

Core Data: Rank link suggestions that begin with the search term first - #83287

Closed
jeryj wants to merge 2 commits into
trunkfrom
update/link-suggestions-prefix-ranking
Closed

jeryj wants to merge 2 commits into
trunkfrom
update/link-suggestions-prefix-ranking

Conversation

@jeryj

@jeryj jeryj commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

What?

Ranks a link suggestion whose title is what was typed, or begins with it, above the rest.

Why?

sortResults scores a title by how many of its tokens match the search query, divided by the title's total token count:

const exactMatchScore = ( exactMatchingTokens.length / titleTokens.length ) * 10;

That normalization marks a long title down for being long, and it cannot see where in the title the match sits. Searching coffee over these four results:

Score Title Type
5.00 Our Coffee page
2.00 Coffee Roasting Guide For Beginners page
10.00 Coffee category
2.50 Decaf Coffee And Tea post

gives this order:

1. Coffee                                [category]
2. Our Coffee                            [page]
3. Decaf Coffee And Tea                  [post]
4. Coffee Roasting Guide For Beginners   [page]

The one title that actually begins with what was typed finishes last. "Coffee Roasting Guide For Beginners" matches coffee perfectly, but across 5 tokens, so it scores 1/5 * 10 = 2.00. "Our Coffee" matches equally well across 2 tokens, so it scores 1/2 * 10 = 5.00. Position in the title counts for nothing.

How?

A tier is computed per result, above the existing score:

  • 2 — the title is exactly what was typed
  • 1 — the title begins with what was typed
  • 0 — anything else

The tier sorts first and the existing score is the tiebreak within a tier, so anything the score already ordered correctly is left alone. Same results, same search:

1. Coffee                                [category]  tier=2
2. Coffee Roasting Guide For Beginners   [page]      tier=1
3. Our Coffee                            [page]      tier=0
4. Decaf Coffee And Tea                  [post]      tier=0

The bottom two keep their relative order from the score (5.00 above 2.50).

A prefix match counts from the first character typed, with no minimum length. On short queries the effect is small, because a one- or two-character search matches too much to have a confident order either way.

Notes for review

  • All three existing sortResults tests pass unchanged, and the tier reinforces two of them. The change is a refinement of the existing ranking rather than a replacement.
  • This affects every consumer of __experimentalFetchLinkSuggestions, so every LinkControl in the editor — paragraph links, image links, the Navigation Link UI. That is deliberate; the flaw is not specific to any one of them.
  • The tier compares the raw search string against the raw title, lowercased and trimmed, rather than comparing tokens. That is what makes it a prefix signal; tokenizing would lose the position information the score is already missing.

Testing Instructions

The change is to a JavaScript API, so this is exercised from the browser console.

  1. Create a page titled Coffee Roasting Guide For Beginners and a page titled Our Coffee.
  2. Open any post in the editor and open the browser console.
  3. Search for coffee:
    const fetch = wp.coreData.__experimentalFetchLinkSuggestions;
    ( await fetch( 'coffee' ) ).map( r => r.title );
    Coffee Roasting Guide For Beginners comes before Our Coffee. On trunk it comes after.
  4. In the editor, select some text, press Cmd/Ctrl+K, and type coffee. The same order should appear in the suggestions list.

Automated coverage

npm run test:unit:vitest -- --run packages/core-data/src/fetch

🤖 Generated with Claude Code

https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9

`sortResults` scored a title by how many of its tokens match the search
query, divided by the title's total token count. That normalization marks
a long title down for being long, and it cannot see where in the title the
match sits. Searching "coffee" ranked "Our Coffee" above "Coffee Roasting
Guide For Beginners", even though only the second one begins with what was
typed.

Rank a title that is exactly what was typed, then a title that begins with
it, above everything else. The existing score is kept as the tiebreak
within a tier, so nothing it already ordered correctly is disturbed: all
three existing `sortResults` tests pass unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9
@jeryj
jeryj requested a review from Mamaduka as a code owner September 21, 2026 18:45
@github-actions github-actions Bot added the [Package] Core data /packages/core-data label Sep 21, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jeryj <jeryj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

📦 Bundle size

Size Change: +51 B (0%)

Total Size: 8.21 MB

📦 View Changed
Filename Size Change
build/scripts/core-data/index.min.js 37.5 kB +51 B (+0.14%)

44ff88a Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric c2f451b trunk % Change
timeToFirstByte 56.5 ms +12.21% -2.39% 55.65 ms +6.38% -1.44% 1.53%
largestContentfulPaint 92 ms +8.7% -4.35% 90 ms +4.44% -2.22% 2.22%
lcpMinusTtfb 34 ms +18.68% -3.09% 33.35 ms +6.45% -1.35% 1.95%
wpBeforeTemplate 28.7 ms +10.03% -2.86% 28.03 ms +1.28% -0.89% 2.39%
wpTemplate 23.88 ms +7.83% -2.81% 23.99 ms +2.58% -2.5% -0.46%
wpTotal 52.93 ms +11.26% -2.57% 52.17 ms +6.23% -1.65% 1.46%
wpMemoryUsage 7.57 MB +0% -0% 7.53 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric c2f451b trunk % Change
timeToFirstByte 47.25 ms +9.31% -1.38% 47.3 ms +4.86% -2.11% -0.11%
largestContentfulPaint 104 ms +1.92% -3.85% 100 ms +4% -0% 4%
lcpMinusTtfb 53.9 ms +4.55% -1.58% 53.95 ms +3.52% -1.85% -0.09%
wpBeforeTemplate 26.31 ms +8.21% -1.1% 26.31 ms +5.97% -1.52% 0%
wpTemplate 17.7 ms +2.49% -1.3% 17.49 ms +3.72% -0.91% 1.2%
wpTotal 44.06 ms +9.69% -0.77% 44.4 ms +4.98% -2.12% -0.77%
wpMemoryUsage 6.19 MB +0% -0% 6.15 MB +0% -0% 0.58%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric c2f451b trunk % Change
mediaProcessingJpeg 394.88 ms +1.1% -0.75% 394.2 ms +0.92% -0.23% 0.17%
mediaProcessingAvif 6050.61 ms +0.26% -0.37% 6034.1 ms +0.03% -0.16% 0.27%
mediaProcessingJpegToAvif 4171.08 ms +0.07% -0.18% 4155.71 ms +0.02% -0.17% 0.37%

media-upload

Metric c2f451b trunk % Change
jpegUploadProcessing 1417.19 ms +4.81% -0.43% 1427.89 ms +0.39% -0.64% -0.75%
pngUploadProcessing 203.02 ms +11.27% -8.97% 210.87 ms +10.31% -5.9% -3.72%
largeJpegUploadProcessing 1404.98 ms +0.72% -0.34% 1406.79 ms +0.63% -0.34% -0.13%
multipleImageUploadProcessing 1551.02 ms +0.41% -0.73% 1575.72 ms +8.92% -0.64% -1.57%

post-editor

Metric c2f451b trunk % Change
serverResponse 532 ms +4.59% -4.95% 504.79 ms +5.42% -2.8% 5.39%
firstPaint 271.83 ms +18.96% -5.21% 219.35 ms +28.19% -5.42% 23.93%
domContentLoaded 1150.52 ms +1.64% -1.21% 1080.07 ms +1.95% -0.79% 6.52%
loaded 1152.04 ms +1.62% -1.21% 1081.24 ms +1.96% -0.77% 6.55%
firstContentfulPaint 474.74 ms +3.03% -1.52% 452.43 ms +1.1% -4.83% 4.93%
firstBlock 3462.38 ms +0.81% -0.59% 3325.91 ms +0.69% -1.29% 4.1%
type 22.26 ms +1.8% -2.34% 19.43 ms +2.73% -3.45% 14.57%
typeWithoutInspector 21.27 ms +9.69% -5.17% 22.35 ms +2.1% -0.85% -4.83%
typeWithTopToolbar 25.67 ms +6.51% -4.25% 24.52 ms +5.95% -5.46% 4.69%
typeContainer 9.58 ms +3.97% -5.53% 9.49 ms +1.05% -10.22% 0.95%
focus 81.33 ms +7.77% -7.8% 76.2 ms +3.73% -6.77% 6.73%
firstFocus 216.4 ms +0% -0% 205.25 ms +0% -0% 5.43%
selectAll 545.66 ms +0.01% -4.47% 497.97 ms +7.23% -2.56% 9.58%
listViewOpen 77.47 ms +5.89% -5.5% 77.59 ms +4.29% -11.64% -0.15%
inserterOpen 23.75 ms +4.29% -12.8% 23.27 ms +13.32% -9.84% 2.06%
inserterHover 3.28 ms +8.54% -8.54% 3.2 ms +11.25% -12.5% 2.5%
inserterSearch 8.13 ms +13.65% -10.33% 7.92 ms +2.15% -9.97% 2.65%
loadPatterns 653.71 ms +2.35% -5.48% 625.24 ms +2.63% -1.66% 4.55%
wpTotal 521.9 ms +4.63% -5.05% 494.9 ms +5.42% -2.92% 5.46%
wpMemoryUsage 13.10 MB +0% -0% 13.06 MB +0% -0% 0.28%
wpDbQueries 53.5 +0.93% -0.93% 54 +0% -1.85% -0.93%

site-editor

Metric c2f451b trunk % Change
serverResponse 326.36 ms +1.72% -10.24% 312.96 ms +2.6% -9.67% 4.28%
firstPaint 183.33 ms +8.5% -10.41% 206.93 ms +14.51% -16.82% -11.4%
domContentLoaded 875.21 ms +0.33% -1.71% 862.31 ms +1.09% -1.14% 1.5%
loaded 876.24 ms +0.35% -1.71% 863.41 ms +1.08% -1.15% 1.49%
firstContentfulPaint 355.46 ms +0.87% -1.94% 352.18 ms +3.07% -1.67% 0.93%
firstBlock 3127.94 ms +1.37% -1.08% 3094.29 ms +1.11% -0.96% 1.09%
type 17.22 ms +2.73% -4.47% 16.54 ms +3.14% -2.72% 4.11%
navigate 94.97 ms +20.43% -2.38% 113.02 ms +2.45% -6.28% -15.97%
loadPatterns 958.53 ms +8.28% -4.54% 970.8 ms +4.79% -7.28% -1.26%
loadPages 1049.48 ms +3.06% -1.22% 1045.09 ms +2.03% -1.92% 0.42%
wpTotal 317.93 ms +1.74% -10.57% 304.58 ms +2.46% -9.98% 4.38%
wpMemoryUsage 12.06 MB +0% -0% 12.02 MB +0% -0% 0.31%
wpDbQueries 44 +0% -2.27% 44 +0% -2.27% 0%

44ff88a Run

🏁 Flaky tests

Show the failures

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

As a site builder, I want to insert a core navigation overlay pattern with CTA and see it on the frontend (Site Editor v2) in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeVisible() failed

Locator:  getByRole('option', { name: /Overlay with site info and CTA/i })
Expected: visible
Received: hidden
Timeout:  5000ms

Call log:
  - Expect "toBeVisible" getByRole('option', { name: /Overlay with site info and CTA/i }) with timeout 5000ms
  - waiting for getByRole('option', { name: /Overlay with site info and CTA/i })
    14 × locator resolved to <div role="option" tabindex="-1" data-base-ui-tooltip-trigger="" aria-label="Overlay with site info and CTA" class="block-editor-block-patterns-list__item" id="core/navigation-overlay-centered-with-extras" aria-describedby="block-editor-block-patterns-list__item-description-4">…</div>
       - unexpected value "hidden"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:227:31
applies the filtered form to the Quick Edit DataForm in /test/e2e/specs/site-editor/view-config-extensibility.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → PUT http://localhost:8889/wp-json/wp/v2/plugins/gutenberg-test-plugins/view-config-extensibility
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.18 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: 3cf64b6a84
    - content-type: application/json
    - content-length: 21
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1790189635%7CzLWpYZ1uxJaHP33Zn3UZOlFMJm2OKCbNhDNu51xmQPw%7Cbebefd959a6b0a0b39e93de01fd369449a9860cc6bfe68aaf7d06ff4b59a4c84; wp-settings-time-1=1790017283

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:112:39)
    at RequestUtils.deactivatePlugin (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts:89:13)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/view-config-extensibility.spec.js:57:3

44ff88a Run

@jeryj
jeryj marked this pull request as draft September 21, 2026 20:12
@jeryj jeryj closed this Sep 22, 2026
jeryj added a commit that referenced this pull request Sep 23, 2026
The prefix ranking landed here rather than in #83287, which is closed. Its
entry travelled with the file when this branch was split out, leaving two
entries describing one change, one of them pointing at nothing.

Also records that the suggestions shown before anything is typed keep
their limit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9
jeryj added a commit that referenced this pull request Oct 1, 2026
The prefix ranking landed here rather than in #83287, which is closed. Its
entry travelled with the file when this branch was split out, leaving two
entries describing one change, one of them pointing at nothing.

Also records that the suggestions shown before anything is typed keep
their limit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Core data /packages/core-data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant