My Jetpack: stabilize product search ranking while typing a category name#50058
My Jetpack: stabilize product search ranking while typing a category name#50058enejb wants to merge 2 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
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., Performanc → Performance) 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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Code Coverage SummaryCoverage changed in 1 file.
|
keoshi
left a comment
There was a problem hiding this comment.
Works great in my testing, thanks for fixing this!
LiamSarsfield
left a comment
There was a problem hiding this comment.
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:
scoreFieldstaking 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
categoryFieldscomment 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.
Fixes #
Proposed changes
PerformancandPerformancereturned the same products but in a different order — items would visibly jump on the final keystroke."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.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.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
Performanc(no trailing "e") and note the result order.eto makePerformance. Confirm the result order does not change (before this fix, items such as Boost would jump down the list).Performance,Security,Growth) still surfaces every item in that category.cd projects/packages/my-jetpack && pnpm test— including the new "keeps a stable order whether a category word is partially or fully typed" test inproducts/test/utils.test.ts.