Commit e9314684 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4530 (Catalogue rating sort broken)

parent 826b7e6f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -626,6 +626,7 @@ We have the following which are either unlikely to be useful, or potentially uns
  - [tt]force_memory_sort__<catalogue-name>[/tt] -- set this to '1' to force an in-memory sort on a particular catalogue (this is slower, but it will sort more accurately by resolving language string fallback and Comcode fully before sorting)
  - [tt]search_do_days_fallback[/tt] -- set this to '0' if you don't want to re-search without a recency filter if no results were found
  - [tt]sitemap_orphans_to_pages[/tt] -- set this to '0' if you don't want orphaned pages to be put under the default Pages page grouping of the Sitemap 
  - [tt]time_sensitive_rankings__<catalogue_name>[/tt] -- set this to a number for catalogue rating sorting to only consider this number of records. This is useful for a upvote/downvote system that is responsive to change in voting pattern.
 - Performance tuning (positive) [not official options as will break normal expectations of how the system will behave / complicate things]
  - [tt]slow_php_dns[/tt] -- set this to '1' if the server has very slow DNS resolution on the web server's main network interface, and therefore to do DNS resolution via the command line instead
  - [tt]lots_of_data_in_*[/tt] -- set this to '1', with '*' replaced with a database table name, if you want the Selectcode mechanism to work with recursive DB lookups rather than one huge flat lookup
+8 −9
Original line number Diff line number Diff line
@@ -623,19 +623,21 @@ function _default_conv_func($db, $info, $catalogue_name, &$extra_join, &$extra_s
    // Special case for ratings
    $matches = ($filter_key == 'compound_rating') ? array('', $info['feedback_type_code']) : array();
    if (($filter_key == 'compound_rating') || (preg_match('#^compound_rating\_\_(.+)#', $filter_key, $matches) != 0)) {
        if ($filter_key == 'compound_rating') {
            $matches[1] .= '__' . $catalogue_name;
        }
        $clause = '(SELECT SUM(rating-1) FROM ' . $db->get_table_prefix() . 'rating rat WHERE ' . db_string_equal_to('rat.rating_for_type', $matches[1]) . ' AND rat.rating_for_id=' . db_cast($table_join_code . '.' . $first_id_field, 'CHAR') . ')';
        $extra_select[$filter_key] = ', ' . $clause . ' AS compound_rating_' . fix_id($matches[1]);
        return array($clause, '', $filter_val);
    }
    $matches = ($filter_key == 'average_rating') ? array('', $info['feedback_type_code']) : array();
    if (($filter_key == 'average_rating') || (preg_match('#^average_rating\_\_(.+)#', $filter_key, $matches) != 0)) {
        if ($filter_key == 'average_rating') {
            $matches[1] .= '__' . $catalogue_name;
        $table_and_where = $db->get_table_prefix() . 'rating rat WHERE ' . db_string_equal_to('rat.rating_for_type', $matches[1]) . ' AND rat.rating_for_id=' . db_cast($table_join_code . '.' . $first_id_field, 'CHAR');
        if ($catalogue_name !== null) {
            $time_sensitivity = get_value('time_sensitive_rankings__' . $catalogue_name, '');
            if ($time_sensitivity != '') {
                $table_and_where = '(SELECT * FROM ' . $table_and_where . ' LIMIT ' . strval(intval($time_sensitivity)) . ') ' . uniqid(''); // TODO: MySQL-only, fix in v11
            }
        }
        $clause = '(SELECT AVG(' . db_cast('rating' , 'FLOAT') . ')/2 FROM ' . $db->get_table_prefix() . 'rating rat WHERE ' . db_string_equal_to('rat.rating_for_type', $matches[1]) . ' AND rat.rating_for_id=' . db_cast($table_join_code . '.' . $first_id_field, 'CHAR') . ')';
        $clause = '(SELECT AVG(' . db_cast('rating' , 'FLOAT') . ')/2 FROM ' . $table_and_where . ')';
        $clause = db_function('COALESCE', array($clause, '2.5'));
        $extra_select[$filter_key] = ', ' . $clause . ' AS average_rating_' . fix_id($matches[1]);
        return array($clause, '', $filter_val);
    }
@@ -643,9 +645,6 @@ function _default_conv_func($db, $info, $catalogue_name, &$extra_join, &$extra_s
    // Random
    $matches = ($filter_key == 'fixed_random') ? array('', $info['feedback_type_code']) : array();
    if (($filter_key == 'fixed_random') || (preg_match('#^fixed_random\_\_(.+)#', $filter_key, $matches) != 0)) {
        if ($filter_key == 'fixed_random') {
            $matches[1] .= '__' . $catalogue_name;
        }
        $clause = db_cast('r.' . $first_id_field, 'INT');
        $clause = '(' . db_function('MOD', array($clause, date('d'))) . ')';
        $extra_select[$filter_key] = ', ' . $clause . ' AS fixed_random_' . fix_id($matches[1]);