Fixes sorting for some search result pages.
Fixed a search issue that added a double comma on ORDER BY clause in some cases.
Closes #18977