Fix export content search to match titles only, ranked by relevance#8048
Open
donnapep wants to merge 1 commit into
Open
Fix export content search to match titles only, ranked by relevance#8048donnapep wants to merge 1 commit into
donnapep wants to merge 1 commit into
Conversation
The export content search fetched /wp/v2/{type} with per_page=20 and
default date ordering. A matching lesson older than 20 newer posts —
even ones matching only in body text — fell outside the window and was
unselectable (#8047).
Restrict the search to post_title and order by relevance. orderby is
set only when a search term is present; WP core rejects
orderby=relevance without a search, and the field fetches with no
search term on mount.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the Export Content tool’s post-picker search (Sensei LMS → Tools → Export Content) so that suggestions are based on title matches only and are ranked by relevance, preventing older title-matching items from being pushed out of the limited suggestion window by newer body-text matches.
Changes:
- Update
PostTokenFieldREST query to usesearch_columns[]=post_title(title-only search) when a search term is present. - Add
orderby=relevance(only when searching) so results are ranked by match quality instead of default date ordering. - Add a unit test to ensure the initial empty-search request does not include
orderby=relevance.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
assets/data-port/export/post-token-field.js |
Adds title-only search + relevance ordering query params for REST suggestions when searching. |
assets/data-port/export/post-token-field.test.js |
Adds a regression test to ensure orderby=relevance is not requested without a search term. |
changelog/fix-export-search-relevance |
Documents the user-facing fix in a patch-level changelog entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+79
to
+89
| it( 'does not request relevance ordering when there is no search term', async () => { | ||
| renderField( { type: 'lesson' } ); | ||
|
|
||
| await waitFor( () => expect( apiFetch ).toHaveBeenCalled() ); | ||
|
|
||
| // WP core rejects `orderby=relevance` without a `search` param, so the | ||
| // initial (empty-search) fetch must fall back to the default ordering. | ||
| expect( apiFetch.mock.calls[ 0 ][ 0 ].path ).not.toContain( | ||
| 'orderby=relevance' | ||
| ); | ||
| } ); |
Contributor
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.
Problem
The Export Content tool's search field (Sensei LMS → Tools → Export Content) failed to find matching lessons/courses/questions. Fixes #8047.
Reported in #8047: searching for a lesson by title returned nothing even though it exists and is published.
PostTokenFieldfetched/wp/v2/{type}?search=…&per_page=20with WordPress core's default date ordering and searched title + content + excerpt. So:Confirmed against learn.wordpress.org data: a search returned 20 lessons, none matching in their title, all newer than the intended target — which was a title match but never appeared.
Fix
When a search term is present, the suggestion fetch now:
search_columns[]=post_title— match titles only (this is a "pick a post by name" field; body matches shouldn't crowd it out).orderby=relevance— rank by match quality instead of date, so a title match isn't pushed past theper_pagecap.Both are
@wordpress/api-fetchquery params — no server changes.search_columnsis a WP core REST param since 6.5; Sensei requires 6.8, so it's always available.orderby=relevanceis set only when searching, because WP core rejects it without asearchparam and the field fetches with no search term on mount.Testing
🤖 Generated with Claude Code