From 6c851270d845c3517d631aff150e23593cf48082 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 4 Feb 2016 16:18:48 -0500 Subject: [PATCH] LP#1549505: Invert popularity sort value so default ASC does what we want Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index b9fae94a01..bf41eb7781 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -869,6 +869,7 @@ sub toSQL { $$flat_plan{with} .= $pop_with; + 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'))" } elsif ($sort_filter eq 'create_date') { @@ -876,9 +877,10 @@ sub toSQL { } elsif ($sort_filter eq 'edit_date') { $rank = "FIRST((SELECT edit_date FROM biblio.record_entry rbr WHERE rbr.id = m.source))"; } elsif ($sort_filter eq 'poprel') { - $rank = '(' . $rel . ') * (1.0 + AVG(COALESCE(pop_with.total_score::NUMERIC,0.0)) / 5.0)'; + $rank = '1.0/((' . $rel . ') * (1.0 + AVG(COALESCE(pop_with.total_score::NUMERIC,0.0)) / 5.0))::NUMERIC'; } elsif ($sort_filter =~ /^pop/) { - $rank = 'AVG(COALESCE(pop_with.total_score::NUMERIC,0.0))'; + $rank = '1.0/(AVG(COALESCE(pop_with.total_score::NUMERIC,0.0)) + 5.0)::NUMERIC'; + $pop_extra_sort = "3 $desc $nullpos,"; } else { # default to rel ranking $rank = $rel; @@ -925,7 +927,7 @@ SELECT $key AS id, WHERE 1=1 $flat_where GROUP BY 1 - ORDER BY 4 $desc $nullpos, 5 DESC $nullpos, 3 DESC + ORDER BY 4 $desc $nullpos, $pop_extra_sort 5 DESC $nullpos, 3 DESC LIMIT $core_limit SQL -- 2.11.0