Commit 551f2d192b7e117c8bc5b9cde37498f015bc5e05
1 parent
b189371f
SUP-1244. Corrected issues with the sorting in the browse view when clicking hea…
…dings which caused the results to remain in their current order instead of sorting, and made sorting case insensitive so that lowercase does not come before uppercase. A search result cannot be ordered Fixed Committed By: Paul Barrett Reviewed by: Megan Watson
Showing
2 changed files
with
24 additions
and
9 deletions
search2.php
| @@ -62,7 +62,8 @@ function search2queryCompare($a, $b) | @@ -62,7 +62,8 @@ function search2queryCompare($a, $b) | ||
| 62 | return 0; | 62 | return 0; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | - $result = ($a->$search2queryColumn < $b->$search2queryColumn)?-1:1; | 65 | + // convert to lowercase for comparison, else sorting will put all lowercase before/after all uppercase |
| 66 | + $result = (strtolower($a->$search2queryColumn) < strtolower($b->$search2queryColumn)) ? -1 : 1; | ||
| 66 | 67 | ||
| 67 | if ($search2queryOrder == 'asc') | 68 | if ($search2queryOrder == 'asc') |
| 68 | return $result; | 69 | return $result; |
| @@ -124,10 +125,20 @@ function search2QuerySort($sSortColumn, $sSortOrder) | @@ -124,10 +125,20 @@ function search2QuerySort($sSortColumn, $sSortOrder) | ||
| 124 | 125 | ||
| 125 | $results = unserialize($_SESSION['search2_results']); | 126 | $results = unserialize($_SESSION['search2_results']); |
| 126 | 127 | ||
| 127 | - usort($results, 'search2queryCompare'); | ||
| 128 | - | ||
| 129 | - $_SESSION['search2_results'] = serialize($results); | ||
| 130 | - | 128 | + // Loop through to find and sort all possible result item types |
| 129 | + foreach($results as $key => $result) | ||
| 130 | + { | ||
| 131 | + // force re-initialisation of $sortresults on each iteration | ||
| 132 | + $sortresults = array(); | ||
| 133 | + $sortresults = $result; | ||
| 134 | + // NOTE: usort may be sufficient here. | ||
| 135 | + // uasort was used because results were disappearing, | ||
| 136 | + // but this may have been related to not using the loop | ||
| 137 | + uasort($sortresults, 'search2queryCompare'); | ||
| 138 | + $results[$key] = $sortresults; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + $_SESSION['search2_results'] = serialize($results); | ||
| 131 | } | 142 | } |
| 132 | 143 | ||
| 133 | /** | 144 | /** |
| @@ -373,7 +384,10 @@ class SearchDispatcher extends KTStandardDispatcher { | @@ -373,7 +384,10 @@ class SearchDispatcher extends KTStandardDispatcher { | ||
| 373 | 384 | ||
| 374 | function do_oldSearchResults() | 385 | function do_oldSearchResults() |
| 375 | { | 386 | { |
| 376 | - $this->oPage->setBreadcrumbDetails(_kt("Search Results")); | 387 | + // call the results sorting function in case of sort options selected |
| 388 | + search2QuerySort(stripslashes($_GET['sort_on']), stripslashes($_GET['sort_order'])); | ||
| 389 | + | ||
| 390 | + $this->oPage->setBreadcrumbDetails(_kt("Search Results")); | ||
| 377 | $this->oPage->title = _kt("Search Results"); | 391 | $this->oPage->title = _kt("Search Results"); |
| 378 | 392 | ||
| 379 | $collection = new AdvancedCollection; | 393 | $collection = new AdvancedCollection; |
| @@ -661,9 +675,9 @@ class SearchDispatcher extends KTStandardDispatcher { | @@ -661,9 +675,9 @@ class SearchDispatcher extends KTStandardDispatcher { | ||
| 661 | $sql .= " AND user_id=$this->curUserId "; | 675 | $sql .= " AND user_id=$this->curUserId "; |
| 662 | } | 676 | } |
| 663 | 677 | ||
| 664 | - | ||
| 665 | DBUtil::runQuery($sql); | 678 | DBUtil::runQuery($sql); |
| 666 | - $this->successRedirectTo('manage', _kt('The saved search was deleted successfully.')); | 679 | + |
| 680 | + $this->successRedirectTo('manage', _kt('The saved search was deleted successfully.')); | ||
| 667 | 681 | ||
| 668 | } | 682 | } |
| 669 | 683 |
search2/search/search.inc.php
| @@ -51,7 +51,8 @@ function rank_compare($a, $b) | @@ -51,7 +51,8 @@ function rank_compare($a, $b) | ||
| 51 | if ($a->Title == $b->Title) | 51 | if ($a->Title == $b->Title) |
| 52 | return 0; | 52 | return 0; |
| 53 | // we'll show docs in ascending order by name | 53 | // we'll show docs in ascending order by name |
| 54 | - return ($a->Title < $b->Title)?-1:1; | 54 | + // strtolower to avoid case issues in sorting |
| 55 | + return (strtolower($a->Title) < strtolower($b->Title)) ? -1 : 1; | ||
| 55 | } | 56 | } |
| 56 | // we want to be in descending order | 57 | // we want to be in descending order |
| 57 | return ($a->Rank > $b->Rank)?-1:1; | 58 | return ($a->Rank > $b->Rank)?-1:1; |