nick-boss-tech opened a new pull request, #5150: URL: https://github.com/apache/solr/pull/5150
🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)* https://issues.apache.org/jira/browse/SOLR-9864 ## What happens today **`SolrQuery.getCopy()` does not copy the sort clauses, so the copy loses its sorts.** `getCopy()` copies the query parameters, including the `sort` parameter. It does not copy the list of sort clauses ([SolrQuery.java L1182-L1188 at base](https://github.com/nick-boss-tech/solr/blob/14c7aac0d151402b00259e2fb9bf5eed7049ec5d/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrQuery.java#L1182-L1188)). Adding a sort to the copy then rewrites `sort` with only the new clause. `getSorts()` on the copy returns an empty list. The ticket lists 4.8.1, 6.3, 7.7, and 9.0 as affected versions. ## What this change does **`getCopy()` also copies the sort clause list.** - The copy gets a new list that holds the same `SortClause` objects ([SolrQuery.java L1187-L1189](https://github.com/nick-boss-tech/solr/blob/b5826e466b9a8664adf11e0f247cff220f2f5953/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrQuery.java#L1187-L1189)). `SortClause` has final fields, so sharing the objects is safe. Changing the copy's sorts does not change the original. - The copy's `getSorts()` now matches the original's. Nothing else in `getCopy()` changes. ## Proof **One new test fails on the base code and passes with the change. All 27 focused tests pass at this head.** - `SolrQueryTest` 17 of 17 at `b5826e466b9a8664adf11e0f247cff220f2f5953`. The new `testGetCopyKeepsSortClauses` fails on the base code at its first comparison, because the copy's sorts are empty. The 16 existing tests pass on the base code and with the change. - `QueryRequestTest` 5 of 5 and `TestUpdateRequest` 5 of 5 at the same head. - Verified 2026-10-05 at `b5826e466b9a8664adf11e0f247cff220f2f5953`. ## Limits **The new test covers a copy with two sorts.** - The new test does not cover a copy of a query with no sorts. In that case the list stays null, as before. - No other copy method in `SolrQuery` changed. Changelog: [`changelog/unreleased/SOLR-9864-solrquery-getcopy-sorts.yml`](https://github.com/nick-boss-tech/solr/blob/b5826e466b9a8664adf11e0f247cff220f2f5953/changelog/unreleased/SOLR-9864-solrquery-getcopy-sorts.yml) (type: fixed) ### AI assistance AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
