Repository navigation
Conversation
Add a `/wp-block-editor/v1/link-suggestions` endpoint that searches posts, terms, post formats and media in a single SQL query, ranks them, and pages the ranked list. `__experimentalFetchLinkSuggestions` now makes one request to it instead of four, and no longer sorts results in the browser. Results that match equally well share each page between the post types and taxonomies they come from. The endpoint also accepts type and subtype filters, exclusions and preferred types, parses searches as `WP_Query` does, caches results, and lets a search plugin supply them through the `link_suggestions_pre_query` filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: -253 B (0%) Total Size: 8.25 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rank pages above other content that matches as well, since a link is more often to a page. Preferring posts lifts them back above pages. - Match media by its title, caption and description, not its file name. Matching the file name joined post meta for every attachment, which was most of the cost of searching media, and a file name is rarely more than the title it was uploaded with. - Count the results in the same query as the page, with a window function, instead of running the whole search a second time. A second count only runs past the last page, or without window functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Normalize titles inside each branch of the union, which is stored as a table, so a title is normalized once instead of again for every score that reads it. - Split titles into words with `REGEXP_REPLACE` where the database has it (MySQL 8.0, MariaDB 10.2), at anything but letters and numbers, as `tokenize()` in core-data did. Older databases keep splitting at the punctuation found in titles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every value in the query now goes through a placeholder: search terms, words, post types, taxonomies, statuses, preferred types, ranks, the user ID and the page. Only table names, the class's own column names and pieces made with `prepare()` are written into the SQL, and pieces are joined without being prepared again. Key the cache on the SQL with the placeholder `prepare()` puts in place of `%` taken out, since it differs between requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds
GET /wp-block-editor/v1/link-suggestions, which searches posts, terms, post formats and media in one SQL query, ranked and paged.__experimentalFetchLinkSuggestionscalls it instead of making four requests and sorting the results in the browser.Related: #83407 (the browser ranking this replaces), #83408, #83652.
Why?
Four merged requests can't be paged: merging page 2 of each skips and repeats results, and past 20 matches of one type the other types never arrive. One ranked list makes each page a slice of it with a known total, so the link UI can load more.
How?
WP_Queryparses them (quoted phrases, stopwords,-word). Each term must be in the title, or for posts and media in the content or excerpt. Media visibility follows its parent post, checked in SQL.type,subtype,type_exclude,subtype_exclude,prefer_types(the shape Navigation: Search every entity type from the link UI #83408 uses forpreferTypes),page,per_page. The JS options are the camelCase names./wp/v2/searchfields (id,title,url,type,subtype,selflink).fetchLinkSuggestionsmaps them to the fields it already returns.$wpdb->prepare(). A search plugin can supply results throughlink_suggestions_pre_query. Results are cached.Performance
Over HTTP, on 50,000 posts and pages, 200,000 media items and 5,000 terms (MariaDB 12.3, median of 5). "Before" is the editor's four requests, in parallel.
Only a word found in most of the site is slower, since every match is scored before paging.
Testing Instructions
Testing Instructions for Keyboard
No interface changes.
Use of AI Tools
Written with Claude Code (Claude Opus 5.5), directed and reviewed by the author.
🤖 Generated with Claude Code