Skip to content

[Ready] SOLR-9864: getCopy() also copies the sort clause list - #5150

Draft
nick-boss-tech wants to merge 8 commits into
apache:mainfrom
nick-boss-tech:solr-9864-submit
Draft

nick-boss-tech wants to merge 8 commits into
apache:mainfrom
nick-boss-tech:solr-9864-submit

Conversation

@nick-boss-tech

@nick-boss-tech nick-boss-tech commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖 (posted on behalf of Nick Shanin)

Ready for review, but held as a draft due to the project's open-PR cap; I'll mark it open on request.

https://issues.apache.org/jira/browse/SOLR-9864

What happens today

SolrQuery.getCopy() copies the sort parameter but not the internal sort-clause list, so the copy's getSorts() is empty.

The copy keeps the serialized sort parameter, so its sorts are not lost until the copy's sort list changes. Adding a sort to the copy rebuilds sort from the empty list, and only the new clause remains. For a query sorted by price asc,id desc, adding score desc to the copy gives score desc instead of price asc,id desc,score desc. The ticket lists 4.8.1, 6.3, 7.7, and 9.0 as affected versions. The copy code is at SolrQuery.java L1182-L1188 at base.

What this change does

getCopy() also copies the sort-clause list.

The copy gets a new ArrayList that holds the same SortClause objects in the same order (SolrQuery.java L1187-L1189). SortClause has final fields, so sharing the objects is safe. Changing the copy's sorts leaves the original unchanged. No other part of getCopy() changes.

Proof

The new test fails on the base code and passes with this change.

testGetCopyKeepsSortClauses fails on base 14c7aac0d151402b00259e2fb9bf5eed7049ec5d: the copy's sort list is empty where the two clauses were expected. A second test, testGetCopyRemoveReplaceAndClearSortClauses, also fails on base: after a sort is removed from the copy, the copy still reports the removed clause. The other 17 SolrQueryTest methods pass on that base, including testGetCopyWithoutSortClauses, which pins the no-sort case.

Verified 2026-10-15 at 0fdc9e97b2b0930641f1d4174e6053c69895e4d3:

  • SolrQueryTest 19 of 19
  • QueryRequestTest 5 of 5
  • TestUpdateRequest 5 of 5

Formatting (tidy), the Error Prone test compile, and :solr:solrj:check -x test also pass.

Limits

The tests cover copies with two sorts, with sorts removed and replaced, and with no sorts.

  • A copy of a query with no sorts keeps a null list, as before. testGetCopyWithoutSortClauses covers that case; it passes on the base code too, since that behavior was already correct.
  • A query set only through the raw sort parameter has no clause list. Parsing that parameter into clauses is outside this change. We can open a follow-up ticket and PR for it on request.
  • Clause elements are shared, not deep-copied. A custom SortClause subclass with mutable state would share that state.
  • The full ./gradlew check has not been run. The focused tests above are the behavior evidence.
  • The four upstream workflows at this head (Solr Tests via Crave, SolrJ Tests, Validate Changelog, Gradle Precommit) show action_required and have not produced results yet.

Changelog: changelog/unreleased/SOLR-9864-solrquery-getcopy-sorts.yml

AI assistance

AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution.

@nick-boss-tech
nick-boss-tech marked this pull request as ready for review October 15, 2026 00:15
@nick-boss-tech nick-boss-tech changed the title SOLR-9864: getCopy() also copies the sort clause list [Ready] SOLR-9864: getCopy() also copies the sort clause list Oct 28, 2026
@nick-boss-tech
nick-boss-tech marked this pull request as draft October 28, 2026 04:44
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.

1 participant