From 0efea6dfefb398283432244e3ab801d5f5e8c3c3 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 24 Aug 2011 14:36:54 -0400 Subject: [PATCH] Protect against div-by-0 for negated words Signed-off-by: Mike Rylander Signed-off-by: Thomas Berezansky --- .../perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 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 167aa35411..5f8f74a3d5 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 @@ -497,7 +497,7 @@ sub toSQL { my $flat_plan = $self->flatten; # generate the relevance ranking - my $rel = "AVG(\n\t\t(" . join(")+\n\t\t(", @{$$flat_plan{rank_list}}) . ")\n\t)"; + my $rel = "AVG(\n\t\t(" . join(")+\n\t\t(", @{$$flat_plan{rank_list}}) . ")\n\t)+1"; # find any supplied sort option my ($sort_filter) = $self->find_filter('sort'); @@ -720,7 +720,7 @@ sub flatten { my $table = $node->table; my $talias = $node->table_alias; - my $node_rank = 'COALESCE(' . $node->rank . " * ${talias}.weight, 1.0)"; + my $node_rank = 'COALESCE(' . $node->rank . " * ${talias}.weight, 0.0)"; my $core_limit = $self->QueryParser->core_limit || 25000; $from .= "\n\tLEFT JOIN (\n\t\tSELECT fe.*, fe_weight.weight, x.tsq /* search */\n\t\t FROM $table AS fe"; -- 2.11.0