QueryParser Driver: Remove Unphrases, add negates user/tsbere/QP-for-2-3
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 10 Oct 2012 21:40:41 +0000 (17:40 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 10 Oct 2012 21:40:41 +0000 (17:40 -0400)
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 7ded478..cb0fe13 100644 (file)
@@ -733,10 +733,11 @@ sub flatten {
                     }
                 }
 
+                my $NOT = '';
+                $NOT = 'NOT ' if $node->negate;
 
-                $where .= '(' . $talias . ".id IS NOT NULL";
+                $where .= "$NOT(" . $talias . ".id IS NOT NULL";
                 $where .= ' AND ' . join(' AND ', map {"${talias}.value ~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->phrases}) if (@{$node->phrases});
-                $where .= ' AND ' . join(' AND ', map {"${talias}.value !~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->unphrases}) if (@{$node->unphrases});
                 $where .= ')';
 
                 push @rank_list, $node_rank;
@@ -766,6 +767,8 @@ sub flatten {
             } else {
                 my $subnode = $node->flatten;
 
+                my $NOT = '';
+                $NOT = 'NOT ' if $node->negate;
                 # strip the trailing bool from the previous loop if there is 
                 # nothing to add to the where within this loop.
                 if ($$subnode{where} eq '()') {
@@ -775,7 +778,7 @@ sub flatten {
                 push(@rank_list, @{$$subnode{rank_list}});
                 $from .= $$subnode{from};
 
-                $where .= "$$subnode{where}" unless $$subnode{where} eq '()';
+                $where .= "$NOT$$subnode{where}" unless $$subnode{where} eq '()';
 
                 if ($$subnode{with}) {
                     $with .= ",\n     " if $with;