Skip to content

Core Data: Surface and prioritize matched results in fetchLinkSuggestions#78733

Open
sarthaknagoshe2002 wants to merge 1 commit into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-76805
Open

Core Data: Surface and prioritize matched results in fetchLinkSuggestions#78733
sarthaknagoshe2002 wants to merge 1 commit into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-76805

Conversation

@sarthaknagoshe2002

Copy link
Copy Markdown
Contributor

What?

Closes #76805

This PR introduces a parallel slug-based lookup to __experimentalFetchLinkSuggestions when a user searches for content. It bypasses the limitation where the core /wp/v2/search endpoint strictly screens text matches against titles and excerpts, entirely leaving out valid matches containing different URL slugs.

Why?

When managing slugs & special character routing (e.g., changing a slug from kursuebersicht to kurse while maintaining the presentation title as Kursübersicht), users inevitably search for pages by their URL paths/slugs inside the Link UI popover.

Because /wp/v2/search completely disregards slug criteria, it yields empty payloads for those keywords. There are zero client-side results available to filter or sort.

How?

  • Implemented sub-queries inside the main link search queue to query content types directly by the exact slug keyword.
  • Introduced targeted fallback requests directly to the content type routes (/wp/v2/posts or /wp/v2/pages) via the slug= argument, extract hidden records & deduplicate them against title matches.
  • Refactored the sortResults calculator by parsing slugs with a clean extractSlug helper and assigning a specialized exact slug scale coefficient (8). This slots slug matching elegantly right beneath an exact title match (10) but completely above fuzzy or string-token fraction overlaps (<1).

Scenario Setup

Create three separate pages in your WordPress dashboard with distinct titles and slugs to test both exact slug matches and fuzzy title matches:

  • Page 1 (Target Page): Title: Kursübersicht | Slug: kurse (The word "kurse" is only in the slug and completely absent from the title).
  • Page 2 (Distractor Page): Title: Advanced Course Material | Slug: advanced-training (The title contains a partial semantic match for the query).
  • Page 3 (Noise Page): Title: Contact Us | Slug: contact | Body Content: "If you have questions about our Kurse, let us know!"

Testing Instructions

  1. Open any post or page for editing, highlight some text, open the link selection wrapper.
  2. Input the exact string kurse into the search field.
  3. Observe the resulting dropdown options.
  4. The page titled Kursübersicht must be successfully pulled into the results list via the new parallel slug lookup path and float to the absolute top of the list due to its exact slug score modifier. It should be followed secondarily by content match (Contact Us), proving that the exact slug match successfully outranks standard fuzzy content matches.

Screenshots or screencast

Before After
image image

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@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: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org>
Co-authored-by: hanneslsm <hanneslsm@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 added the [Package] Core data /packages/core-data label May 27, 2026
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.

LinkUI: Prioritize pages with matching slug

1 participant