From 3c17eaed6b4b1f2bd404c55f6d64bcde5893ce1e Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 4 Feb 2016 17:48:02 -0500 Subject: [PATCH] LP#1549505: Correct 1) ultimate tie-breaker sort 2) secondary sort for popularity Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 bf41eb7781..3e3b017227 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 @@ -801,7 +801,6 @@ sub toSQL { $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}) { @@ -824,8 +823,6 @@ sub toSQL { $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')); @@ -869,6 +866,7 @@ sub toSQL { $$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'))" @@ -880,10 +878,11 @@ sub toSQL { $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'; -- 2.11.0