Skip to content

fix: process orderByParams before baseSortParams to preserve sort order for _score and custom fields - #172

Open
zh-hanlabs wants to merge 1 commit into
dromara:mainfrom
zh-hanlabs:fix/score-order-in-sort
Open

zh-hanlabs wants to merge 1 commit into
dromara:mainfrom
zh-hanlabs:fix/score-order-in-sort

Conversation

@zh-hanlabs

Copy link
Copy Markdown

What does this PR do?

Reorders the sort parameter processing in WrapperProcessor.setSort() so that orderByParams (set via orderBy(OrderByParam)) are appended to the DSL sort array before baseSortParams (set via orderByAsc/orderByDesc).

Why

Currently, setSort() processes baseSortParams first and orderByParams second. When a user calls wrapper.orderBy(scoreParam).orderByAsc(...).orderByDesc(...), the _score parameter goes into orderByParams while the field sorts go into baseSortParams. Since baseSortParams is processed first, _score always ends up at the end of the DSL sort array regardless of call order, producing incorrect sorting.

After this change, orderByParams are processed first, so the user-intended sort order is preserved in the generated DSL.

How to verify

  1. Create a query with wrapper.orderBy(scoreParam).orderByAsc(status).orderByDesc(startDate)
  2. Inspect the generated DSL — _score should now appear first in the sort array, followed by status and startDate

Closes #164

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.

_score 排序字段在 orderBy 中被放到最后,导致排序不符合预期

1 participant