+use strict;
+use warnings;
+
package OpenILS::Application::Storage::Driver::Pg::QueryParser;
use OpenILS::Application::Storage::QueryParser;
use base 'QueryParser';
if ($filter) {
my @fargs = @{$filter->args};
- if (@fargs > 1) {
- $dyn_filters{$f} = "( " .
+ if (@fargs > 1 || $filter->negate) {
+ my $NOT = $filter->negate ? 'NOT' : '';
+ $dyn_filters{$f} = "$NOT( " .
join(
" OR ",
map { "mrd.attrs \@> hstore('$col', " . $self->QueryParser->quote_value($_) . ")" } @fargs
@field_ids = @{ $self->QueryParser->facet_field_ids_by_class( $node->classname ) };
}
- $from .= "\n\tJOIN /* facet */ metabib.facet_entry $talias ON (\n\t\tm.source = ${talias}.source\n\t\t".
+ my $join_type = $node->negate ? 'LEFT' : 'INNER';
+ $from .= "\n\t$join_type JOIN /* facet */ metabib.facet_entry $talias ON (\n\t\tm.source = ${talias}.source\n\t\t".
"AND SUBSTRING(${talias}.value,1,1024) IN (" . join(",", map { $self->QueryParser->quote_value($_) } @{$node->values}) . ")\n\t\t".
"AND ${talias}.field IN (". join(',', @field_ids) . ")\n\t)";
- $where .= 'TRUE';
+ $where .= $node->negate ? "${talias}.id IS NULL" : 'TRUE';
} else {
my $subnode = $node->flatten;
+use strict;
+use warnings;
+
package QueryParser;
use OpenSRF::Utils::JSON;
our %parser_config = (
# Build the filter and modifier uber-regexps
- my $facet_re = '^\s*((?:' . join( '|', @{$pkg->facet_classes}) . ')(?:\|\w+)*)\[(.+?)\]';
+ my $facet_re = '^\s*(-?)((?:' . join( '|', @{$pkg->facet_classes}) . ')(?:\|\w+)*)\[(.+?)\]';
warn " Facet RE: $facet_re\n" if $self->debug;
- my $filter_re = '^\s*(' . join( '|', @{$pkg->filters}) . ')\(([^()]+)\)';
- my $filter_as_class_re = '^\s*(' . join( '|', @{$pkg->filters}) . '):\s*(\S+)';
+ my $filter_re = '^\s*(-?)(' . join( '|', @{$pkg->filters}) . ')\(([^()]+)\)';
+ my $filter_as_class_re = '^\s*(-?)(' . join( '|', @{$pkg->filters}) . '):\s*(\S+)';
my $modifier_re = '^\s*'.$modifier_tag_re.'(' . join( '|', @{$pkg->modifiers}) . ')\b';
my $modifier_as_class_re = '^\s*(' . join( '|', @{$pkg->modifiers}) . '):\s*(\S+)';
$last_type = '';
} elsif ($self->filter_count && /$filter_re/) { # found a filter
- warn "Encountered search filter: $1 set to $2\n" if $self->debug;
+ warn "Encountered search filter: $1$2 set to $3\n" if $self->debug;
+ my $negate = ($1 eq '-') ? 1 : 0;
$_ = $';
- $struct->new_filter( $1 => [ split '[, ]+', $2 ] );
+ $struct->new_filter( $2 => [ split '[,]+', $3 ], $negate );
$last_type = '';
} elsif ($self->filter_count && /$filter_as_class_re/) { # found a filter
- warn "Encountered search filter: $1 set to $2\n" if $self->debug;
+ warn "Encountered search filter: $1$2 set to $3\n" if $self->debug;
+ my $negate = ($1 eq '-') ? 1 : 0;
$_ = $';
- $struct->new_filter( $1 => [ split '[, ]+', $2 ] );
+ $struct->new_filter( $2 => [ split '[,]+', $3 ], $negate );
$last_type = '';
} elsif ($self->modifier_count && /$modifier_re/) { # found a modifier
$last_type = 'OR';
} elsif ($self->facet_class_count && /$facet_re/) { # changing current class
- warn "Encountered facet: $1 => $2\n" if $self->debug;
+ warn "Encountered facet: $1$2 => $3\n" if $self->debug;
- my $facet = $1;
- my $facet_value = [ split '\s*#\s*', $2 ];
- $struct->new_facet( $facet => $facet_value );
+ my $negate = ($1 eq '-') ? 1 : 0;
+ my $facet = $2;
+ my $facet_value = [ split '\s*#\s*', $3 ];
+ $struct->new_facet( $facet => $facet_value, $negate );
$_ = $';
$last_type = '';
my $pkg = ref($self) || $self;
my $name = shift;
my $args = shift;
+ my $negate = shift;
- my $node = do{$pkg.'::facet'}->new( plan => $self, name => $name, 'values' => $args );
+ my $node = do{$pkg.'::facet'}->new( plan => $self, name => $name, 'values' => $args, negate => $negate );
$self->add_node( $node );
return $node;
my $pkg = ref($self) || $self;
my $name = shift;
my $args = shift;
+ my $negate = shift;
- my $node = do{$pkg.'::filter'}->new( plan => $self, name => $name, args => $args );
+ my $node = do{$pkg.'::filter'}->new( plan => $self, name => $name, args => $args, negate => $negate );
$self->add_filter( $node );
return $node;
return $self->{name};
}
+sub negate {
+ my $self = shift;
+ return $self->{negate};
+}
+
sub args {
my $self = shift;
return $self->{args};
return $self->{name};
}
+sub negate {
+ my $self = shift;
+ return $self->{negate};
+}
+
sub values {
my $self = shift;
return $self->{'values'};