From b7da3f582a6ec388a312170fcd5ef4123c634735 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 24 Aug 2011 13:44:04 -0400 Subject: [PATCH] Track count of dummy atoms and use a NULL tsquery when all dummy Signed-off-by: Mike Rylander Signed-off-by: Thomas Berezansky --- .../Application/Storage/Driver/Pg/QueryParser.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 e108802a0c..167aa35411 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 @@ -726,7 +726,7 @@ sub flatten { $from .= "\n\tLEFT JOIN (\n\t\tSELECT fe.*, fe_weight.weight, x.tsq /* search */\n\t\t FROM $table AS fe"; $from .= "\n\t\t\tJOIN config.metabib_field AS fe_weight ON (fe_weight.id = fe.field)"; - if ($node->tsquery) { + if ($node->dummy_count < @{$node->only_atoms} ) { $from .= "\n\t\t\tJOIN (SELECT ". $node->tsquery ." AS tsq ) AS x ON (fe.index_vector @@ x.tsq)"; } else { $from .= "\n\t\t\t, (SELECT NULL::tsquery AS tsq ) AS x"; @@ -857,8 +857,6 @@ sub sql { my $self = shift; my $sql = shift; - return undef if $self->{dummy}; - $self->{sql} = $sql if ($sql); return $self->{sql} if ($self->{sql}); @@ -870,6 +868,8 @@ sub buildSQL { my $classname = $self->node->classname; + return $self->sql("to_tsquery('$classname','')") if $self->{dummy}; + my $normalizers = $self->node->plan->QueryParser->query_normalizers( $classname ); my $fields = $self->node->fields; @@ -919,15 +919,23 @@ use base 'QueryParser::query_plan::node'; sub only_atoms { my $self = shift; + $self->{dummy_count} = 0; + my $atoms = $self->query_atoms; my @only_atoms; for my $a (@$atoms) { push(@only_atoms, $a) if (ref($a) && $a->isa('QueryParser::query_plan::node::atom')); + $self->{dummy_count}++ if (ref($a) && $a->{dummy}); } return \@only_atoms; } +sub dummy_count { + my $self = shift; + return $self->{dummy_count}; +} + sub table { my $self = shift; my $table = shift; @@ -956,9 +964,7 @@ sub tsquery { for my $atom (@{$self->query_atoms}) { if (ref($atom)) { - my $sql = $atom->sql; - next if !defined($sql); - $self->{tsquery} .= "\n\t\t\t" .$sql; + $self->{tsquery} .= "\n\t\t\t" .$atom->sql; } else { $self->{tsquery} .= $atom x 2; } -- 2.11.0