SCIX-889 fix(search): sort operator queries by score instead of user preference#889
Merged
thostetler merged 2 commits intoJun 22, 2026
Conversation
…preference Second-order operator queries (trending, reviews, useful, similar) were sorted by the user's saved default sort instead of relevance score. Added getDefaultSortForQuery() to detect these operators and apply score desc at both submit sites (home page and search page), matching the Explore menu path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #889 +/- ##
========================================
+ Coverage 64.2% 66.0% +1.9%
========================================
Files 350 338 -12
Lines 41492 40070 -1422
Branches 2010 2024 +14
========================================
- Hits 26602 26424 -178
+ Misses 14847 13604 -1243
+ Partials 43 42 -1
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Risk summary: Low-to-medium regression risk. The behavior change is small and well-targeted, but the new operator-detection regex may be overly permissive and could override sort for some non-operator queries.
Findings (priority order):
- medium — Operator detection regex can match operator tokens inside fielded/quoted queries and unintentionally override sort.
- Impact: users could lose their intended sort for queries that merely contain
trending(/reviews(etc. as text. - Location:
src/utils/common/search.ts:178 - Minimal fix: constrain detection to start-of-string or whitespace (optionally allowing leading
+/-). - Confidence: medium
- Impact: users could lose their intended sort for queries that merely contain
Changes:
- Added
getDefaultSortForQuery()to forcescore descfor second-order operator queries, otherwise preserve a fallback sort. - Applied the sort override logic to manual submit handlers on both the home page and the search page.
- Added unit tests covering operator detection and passthrough behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/utils/common/search.ts | Adds query-aware default sort selection for second-order operators. |
| src/utils/common/tests/search.test.ts | Adds unit tests validating operator detection and fallback behavior. |
| src/pages/search/index.tsx | Uses query-aware default sort on manual submit from the search page. |
| src/pages/index.tsx | Uses query-aware default sort on manual submit from the home page. |
shinyichen
approved these changes
Jun 22, 2026
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.
Manually typing a second-order operator query (trending, reviews, useful, similar) used the user's saved default sort instead of score desc. The Explore menu path already injected the correct sort; only the manual submit handlers were affected.