Skip to content

Fix export content search to match titles only, ranked by relevance#8048

Open
donnapep wants to merge 1 commit into
trunkfrom
fix/export-search-relevance-ordering
Open

Fix export content search to match titles only, ranked by relevance#8048
donnapep wants to merge 1 commit into
trunkfrom
fix/export-search-relevance-ordering

Conversation

@donnapep

@donnapep donnapep commented Jul 1, 2026

Copy link
Copy Markdown
Member

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.

PostTokenField fetched /wp/v2/{type}?search=…&per_page=20 with WordPress core's default date ordering and searched title + content + excerpt. So:

  • Results were the newest 20 matches, not the best 20.
  • Posts matching only in their body text consumed slots.
  • A matching post older than 20 such posts fell outside the window and was unselectable.

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:

  • Adds search_columns[]=post_title — match titles only (this is a "pick a post by name" field; body matches shouldn't crowd it out).
  • Adds orderby=relevance — rank by match quality instead of date, so a title match isn't pushed past the per_page cap.

Both are @wordpress/api-fetch query params — no server changes. search_columns is a WP core REST param since 6.5; Sensei requires 6.8, so it's always available. orderby=relevance is set only when searching, because WP core rejects it without a search param and the field fetches with no search term on mount.

Testing

  1. On a site with 20+ lessons, create a lesson whose title matches a term (e.g. "Open source basics") with an older publish date than 20+ other lessons that mention that term only in their body.
  2. Sensei LMS → Tools → Export Content → select Lessons.
  3. Search for the title term.
  4. The lesson appears in the suggestions and is selectable.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings July 1, 2026 12:21

Copilot AI 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.

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 PostTokenField REST query to use search_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'
);
} );
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

WordPress Playground Preview

The changes in this pull request can previewed and tested using a WordPress Playground instance.

Open WordPress Playground Preview

@donnapep donnapep added this to the 4.26.2 milestone Jul 1, 2026
@donnapep donnapep self-assigned this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lesson export search not working on Learn WordPress

2 participants