$rel = "($rel * COALESCE( NULLIF( FIRST(mrv.vlist \@> ARRAY[lang_with.id]), FALSE )::INT * $plw, 1))";
$$flat_plan{uses_mrv} = 1;
}
- $rel = "1.0/($rel)::NUMERIC";
my $mrv_join = '';
if ($$flat_plan{uses_mrv}) {
$bre_join = 'INNER JOIN biblio.record_entry bre ON m.source = bre.id';
}
- my $rank = $rel;
-
my $desc = 'ASC';
$desc = 'DESC' if ($self->find_modifier('descending'));
$$flat_plan{with} .= $pop_with;
+ my $rank;
my $pop_extra_sort = '';
if (grep {$_ eq $sort_filter} @{$self->QueryParser->dynamic_sorters}) {
$rank = "FIRST((SELECT value FROM metabib.record_sorter rbr WHERE rbr.source = m.source and attr = '$sort_filter'))"
$rank = '1.0/((' . $rel . ') * (1.0 + AVG(COALESCE(pop_with.total_score::NUMERIC,0.0)) / 5.0))::NUMERIC';
} elsif ($sort_filter =~ /^pop/) {
$rank = '1.0/(AVG(COALESCE(pop_with.total_score::NUMERIC,0.0)) + 5.0)::NUMERIC';
- $pop_extra_sort = "3 $desc $nullpos,";
+ my $pop_desc = $desc eq 'ASC' ? 'DESC' : 'ASC';
+ $pop_extra_sort = "3 $pop_desc $nullpos,";
} else {
# default to rel ranking
- $rank = $rel;
+ $rank = "1.0/($rel)::NUMERIC";
}
my $key = 'm.source';