QueryParser Driver: Remove Unphrases, add negates
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 10 Oct 2012 21:23:43 +0000 (17:23 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 15 Feb 2013 20:39:49 +0000 (15:39 -0500)
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 16f4731..9afb754 100644 (file)
@@ -929,18 +929,15 @@ sub flatten {
                     }
                 }
 
                     }
                 }
 
+                my $NOT = '';
+                $NOT = 'NOT ' if $node->negate;
 
 
-                $where .= '(' . $talias . ".id IS NOT NULL";
+                $where .= "$NOT(" . $talias . ".id IS NOT NULL";
                 if (@{$node->phrases}) {
                     $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->phrases});
                 }
-                if (@{$node->unphrases}) {
-                    $where .= ' AND ' . join(' AND ', map {
-                        "${talias}.value !~* ".$self->QueryParser->quote_phrase_value($_)
-                    } @{$node->unphrases});
-                }
                 for my $atom (@{$node->only_real_atoms}) {
                     next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/;
                     $where .= " AND ${talias}.value ~* ".$self->QueryParser->quote_phrase_value($atom->{content});
                 for my $atom (@{$node->only_real_atoms}) {
                     next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/;
                     $where .= " AND ${talias}.value ~* ".$self->QueryParser->quote_phrase_value($atom->{content});
@@ -989,8 +986,11 @@ sub flatten {
                 push(@rank_list, @{$$subnode{rank_list}});
                 $from .= $$subnode{from};
 
                 push(@rank_list, @{$$subnode{rank_list}});
                 $from .= $$subnode{from};
 
+                my $NOT = '';
+                $NOT = 'NOT ' if $node->negate;
+
                 if ($$subnode{where} ne '') {
                 if ($$subnode{where} ne '') {
-                    $where .= "(\n"
+                    $where .= "$NOT(\n"
                            . ${spc} x ($self->plan_level + 6) . $$subnode{where} . "\n"
                            . ${spc} x ($self->plan_level + 5) . ')';
                 }
                            . ${spc} x ($self->plan_level + 6) . $$subnode{where} . "\n"
                            . ${spc} x ($self->plan_level + 5) . ')';
                 }