fix: auto-switch to relevance sort when search query is entered#778
fix: auto-switch to relevance sort when search query is entered#778oolong-tea-2026 wants to merge 2 commits intoopenclaw:mainfrom
Conversation
When users enter a search query on the /skills page, sort order should automatically switch to 'relevance' so results are ranked by semantic similarity + lexical match rather than downloads. Previously, the beforeLoad redirect in skills/index.tsx always injects sort=downloads when no sort param is present. Since all entry points (Browse Skills button, Header Skills link, Header Search link) arrive without a sort param, users always end up with sort=downloads in the URL. When they then type a search query, the sort stays as 'downloads' because search.sort is already set, and the fallback to 'relevance' never triggers. This means the vector search scoring (semantic similarity + lexical boost + popularity boost) is computed but then ignored in favor of pure download count ordering. Fix: when hasQuery is true, always use 'relevance' sort regardless of the current search.sort value. Users who explicitly want a different sort during search can still select one from the dropdown, but relevance is always the starting point when a query is present.
|
@oolong-tea-2026 is attempting to deploy a commit to the Amantus Machina Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4851ba24fb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const sort: SortKey = hasQuery | ||
| ? 'relevance' |
There was a problem hiding this comment.
Preserve manual sort override for active queries
When q is non-empty, useSkillsBrowseModel now hardcodes sort to relevance, so onSortChange can still write search.sort to the URL but the selected sort is never actually applied while searching. This regresses behavior for users who intentionally switch to downloads/stars/etc. during a search (the dropdown choice is effectively ignored until the query is cleared).
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes a real UX bug where search results on the The one-line logic change in Key points:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/routes/skills/-useSkillsBrowseModel.ts
Line: 51-53
Comment:
**Manual sort override silently ignored while searching**
The new logic unconditionally returns `'relevance'` whenever `hasQuery` is true, meaning the sort dropdown becomes non-functional during an active search. When a user selects `'downloads'` or `'stars'` from the dropdown while searching, `onSortChange` writes `search.sort` to the URL, but the computed `sort` always evaluates to `'relevance'` regardless — the actual sort used never matches the user's selection.
The PR description's "After" column states the manual sort selection is **"Respected"**, but the code contradicts this. The original code correctly threaded `search.sort` through for any manually-chosen value while a query was active; only the implicit default was broken.
To preserve the ability to manually override the sort during search, the auto-switch to relevance should only apply when `search.sort` has not been explicitly set by the user (i.e. when it is `undefined`). The `beforeLoad` injection of `sort=downloads` into the URL on cold page loads would still bypass this intent, which is a related but separate root-cause issue worth addressing alongside this fix.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 4851ba2 |
| const sort: SortKey = hasQuery | ||
| ? 'relevance' | ||
| : (search.sort === 'relevance' ? 'downloads' : (search.sort ?? 'downloads')) |
There was a problem hiding this comment.
Manual sort override silently ignored while searching
The new logic unconditionally returns 'relevance' whenever hasQuery is true, meaning the sort dropdown becomes non-functional during an active search. When a user selects 'downloads' or 'stars' from the dropdown while searching, onSortChange writes search.sort to the URL, but the computed sort always evaluates to 'relevance' regardless — the actual sort used never matches the user's selection.
The PR description's "After" column states the manual sort selection is "Respected", but the code contradicts this. The original code correctly threaded search.sort through for any manually-chosen value while a query was active; only the implicit default was broken.
To preserve the ability to manually override the sort during search, the auto-switch to relevance should only apply when search.sort has not been explicitly set by the user (i.e. when it is undefined). The beforeLoad injection of sort=downloads into the URL on cold page loads would still bypass this intent, which is a related but separate root-cause issue worth addressing alongside this fix.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/routes/skills/-useSkillsBrowseModel.ts
Line: 51-53
Comment:
**Manual sort override silently ignored while searching**
The new logic unconditionally returns `'relevance'` whenever `hasQuery` is true, meaning the sort dropdown becomes non-functional during an active search. When a user selects `'downloads'` or `'stars'` from the dropdown while searching, `onSortChange` writes `search.sort` to the URL, but the computed `sort` always evaluates to `'relevance'` regardless — the actual sort used never matches the user's selection.
The PR description's "After" column states the manual sort selection is **"Respected"**, but the code contradicts this. The original code correctly threaded `search.sort` through for any manually-chosen value while a query was active; only the implicit default was broken.
To preserve the ability to manually override the sort during search, the auto-switch to relevance should only apply when `search.sort` has not been explicitly set by the user (i.e. when it is `undefined`). The `beforeLoad` injection of `sort=downloads` into the URL on cold page loads would still bypass this intent, which is a related but separate root-cause issue worth addressing alongside this fix.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Good catch! Fixed in fdf9654. The new approach: onQueryChange clears the URL sort param when entering a search query (so search.sort ?? 'relevance' kicks in as default), but manual dropdown selection writes to search.sort and takes precedence. This preserves user overrides while fixing the original bug where beforeLoad-injected sort=downloads persisted through search.
Address review feedback from codex and greptile bots: the previous change unconditionally forced 'relevance' sort when a query was present, which made the sort dropdown non-functional during search. New approach: - When user types a search query, onQueryChange clears the URL sort param (removing the beforeLoad-injected 'downloads'). This lets the fallback `search.sort ?? 'relevance'` kick in. - When user manually selects a sort from the dropdown during search, onSortChange writes it to search.sort, which takes precedence over the 'relevance' fallback. - When user clears the query, the sort param stays as-is or falls back to 'downloads' for browse mode. This correctly handles all scenarios: 1. Browse → search: auto-switches to relevance ✅ 2. Search + manual sort override: respected ✅ 3. Clear search → back to downloads: ✅
Problem
When users search for skills on the
/skillspage, results are always sorted by downloads instead of relevance, making the vector search scoring (semantic similarity + lexical boost) effectively useless.Root cause
The
beforeLoadredirect inskills/index.tsxinjectssort=downloadswhenever no sort param is present. Since all entry points (Browse Skills button, Header Skills link, Header Search link) arrive without a sort param, the URL always becomes?sort=downloads.When the user then types a search query, the sort computation in
useSkillsBrowseModel.tschecks:Because
search.sortis already"downloads"(notundefined), the??fallback to"relevance"never triggers.Impact
100% of normal-path users are affected. The only way to get relevance-based search results is to manually select "relevance" from the sort dropdown, which most users never do.
This means skills with high semantic relevance to a query but low download counts are buried behind popular but less relevant results.
Reproduction
sort=downloadsFix
When
hasQueryis true, always userelevancesort. When query is cleared, fall back to the URL sort param ordownloads.This is a one-line logic change in
useSkillsBrowseModel.ts. The sort dropdown still allows users to manually override to any sort order during search.Before / After
downloadsrelevancedownloadsdownloads