From 513a9cd86e577918e8b71aac360b882c2e312b44 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Wed, 10 Oct 2012 17:40:41 -0400 Subject: [PATCH] QueryParser Driver: Remove Unphrases, add negates Signed-off-by: Thomas Berezansky --- .../lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 9 ++++++--- 1 file changed, 6 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 7ded478467..cb0fe13b5f 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 @@ -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; -- 2.11.0