Protect against div-by-0 for negated words
authorMike Rylander <mrylander@gmail.com>
Wed, 24 Aug 2011 18:36:54 +0000 (14:36 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 24 Aug 2011 18:45:15 +0000 (14:45 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 167aa35..5f8f74a 100644 (file)
@@ -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";