From 551f2d192b7e117c8bc5b9cde37498f015bc5e05 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Thu, 2 Apr 2009 11:59:10 +0200 Subject: [PATCH] SUP-1244. Corrected issues with the sorting in the browse view when clicking headings 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. --- search2.php | 30 ++++++++++++++++++++++-------- search2/search/search.inc.php | 3 ++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/search2.php b/search2.php index 97bd118..74ed5bd 100644 --- a/search2.php +++ b/search2.php @@ -62,7 +62,8 @@ function search2queryCompare($a, $b) return 0; } - $result = ($a->$search2queryColumn < $b->$search2queryColumn)?-1:1; + // convert to lowercase for comparison, else sorting will put all lowercase before/after all uppercase + $result = (strtolower($a->$search2queryColumn) < strtolower($b->$search2queryColumn)) ? -1 : 1; if ($search2queryOrder == 'asc') return $result; @@ -124,10 +125,20 @@ function search2QuerySort($sSortColumn, $sSortOrder) $results = unserialize($_SESSION['search2_results']); - usort($results, 'search2queryCompare'); - - $_SESSION['search2_results'] = serialize($results); - + // Loop through to find and sort all possible result item types + foreach($results as $key => $result) + { + // force re-initialisation of $sortresults on each iteration + $sortresults = array(); + $sortresults = $result; + // NOTE: usort may be sufficient here. + // uasort was used because results were disappearing, + // but this may have been related to not using the loop + uasort($sortresults, 'search2queryCompare'); + $results[$key] = $sortresults; + } + + $_SESSION['search2_results'] = serialize($results); } /** @@ -373,7 +384,10 @@ class SearchDispatcher extends KTStandardDispatcher { function do_oldSearchResults() { - $this->oPage->setBreadcrumbDetails(_kt("Search Results")); + // call the results sorting function in case of sort options selected + search2QuerySort(stripslashes($_GET['sort_on']), stripslashes($_GET['sort_order'])); + + $this->oPage->setBreadcrumbDetails(_kt("Search Results")); $this->oPage->title = _kt("Search Results"); $collection = new AdvancedCollection; @@ -661,9 +675,9 @@ class SearchDispatcher extends KTStandardDispatcher { $sql .= " AND user_id=$this->curUserId "; } - DBUtil::runQuery($sql); - $this->successRedirectTo('manage', _kt('The saved search was deleted successfully.')); + + $this->successRedirectTo('manage', _kt('The saved search was deleted successfully.')); } diff --git a/search2/search/search.inc.php b/search2/search/search.inc.php index ac43fce..e4d6cec 100755 --- a/search2/search/search.inc.php +++ b/search2/search/search.inc.php @@ -51,7 +51,8 @@ function rank_compare($a, $b) if ($a->Title == $b->Title) return 0; // we'll show docs in ascending order by name - return ($a->Title < $b->Title)?-1:1; + // strtolower to avoid case issues in sorting + return (strtolower($a->Title) < strtolower($b->Title)) ? -1 : 1; } // we want to be in descending order return ($a->Rank > $b->Rank)?-1:1; -- libgit2 0.21.4