Skip to content

My Jetpack: stabilize product search ranking while typing a category name#50058

Open
enejb wants to merge 2 commits into
trunkfrom
fix/my-jetpack-search-category-ranking
Open

My Jetpack: stabilize product search ranking while typing a category name#50058
enejb wants to merge 2 commits into
trunkfrom
fix/my-jetpack-search-category-ranking

Conversation

@enejb

@enejb enejb commented Jun 29, 2026

Copy link
Copy Markdown
Member

Fixes #

Proposed changes

  • Fixes an inconsistency in My Jetpack → Products search where finishing a category word reshuffled the results. Typing Performanc and Performance returned the same products but in a different order — items would visibly jump on the final keystroke.
  • Root cause: category labels were scored as a single space-joined string (e.g. "Performance Recommended" for an item in two categories). A complete category word can only ever prefix-match such a joined label, never exactly match it — so multi-category items missed the exact-match relevance bonus that single-category items got, and got overtaken once the word was completed.
  • Fix: a new categoryFields() helper emits one scored field per category label. Combined with the existing "best field wins" scoring, a multi-category item can now exact-match a single category word just like a single-category item, so completing the word boosts all matching items equally and the order stays stable.
  • Added a regression test asserting partial vs. complete category words return the same order.

This builds on #50056 (search result de-duplication) and is scoped to ranking stability only.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • In wp-admin, go to Jetpack → My Jetpack → Products.
  • In the search box, type Performanc (no trailing "e") and note the result order.
  • Type the final e to make Performance. Confirm the result order does not change (before this fix, items such as Boost would jump down the list).
  • Confirm category search still works — typing a full category name (Performance, Security, Growth) still surfaces every item in that category.
  • Run the unit tests: cd projects/packages/my-jetpack && pnpm test — including the new "keeps a stable order whether a category word is partially or fully typed" test in products/test/utils.test.ts.

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/my-jetpack-search-category-ranking branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/my-jetpack-search-category-ranking

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 29, 2026
@enejb enejb requested review from a team and keoshi June 29, 2026 23:44

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 stabilizes My Jetpack → Products search ranking when users type a category name, preventing result reordering on the final keystroke (e.g., PerformancPerformance) by changing how category labels are scored during relevance ranking.

Changes:

  • Split category scoring into one weighted field per category label (categoryFields) instead of scoring a single space-joined string.
  • Update unified search ranking (searchAndRankItems) to pass category labels as arrays to scoring helpers.
  • Add a regression test ensuring partial vs. complete category typing yields the same result order.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
projects/packages/my-jetpack/changelog/fix-my-jetpack-search-category-ranking Adds a changelog entry for the ranking-stability fix.
projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/utils.ts Adjusts category scoring to be per-label to avoid reshuffling on exact-match completion.
projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/utils.test.ts Adds regression coverage for stable ordering between partial and full category-word input.

Comment thread projects/packages/my-jetpack/changelog/fix-my-jetpack-search-category-ranking Outdated
@enejb enejb added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jun 29, 2026
@enejb enejb added this to the 16.1 milestone Jun 29, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/utils.ts 70/85 (82.35%) 0.21% 0 💚

Full summary · PHP report · JS report

@keoshi keoshi 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.

Works great in my testing, thanks for fixing this!

@LiamSarsfield LiamSarsfield 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.

Nice clean fix. Scoring each label on its own reads better than the joined string, and the regression test covers the partial-vs-complete reshuffle.

Two small, optional things:

  • It leans on one thing: scoreFields taking the best field per term with AND semantics, now that categories are separate fields. A multi-word query test would cover it. Something like an item in ['Performance','Recommended'] matching "performance recommended" while a ['Performance']-only item drops out. That's the path a refactor could break without anyone noticing.

  • Tiny one: the categoryFields comment says the joined label "could only ever prefix-match, never exact-match." That held for multi-category items, but a single-category item's joined string already exact-matched. Worth tightening so the next reader gets the right reason.

Neither blocks anything. Happy to see it ship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants