use OpenSRF::Utils::Logger qw($logger);
use Data::Dumper;
my $U = 'OpenILS::Application::AppUtils';
-use OpenSRF::Utils::Logger qw/$logger/;
my ${spc} = ' ' x 2;
sub subquery_callback {
my $self = shift;
my $value = shift;
my $wb = shift;
-
+
my $left_anchored = '';
my $right_anchored = '';
my $left_wb = 0;
$value =~ s/^[*\^]// if $left_anchored;
$value =~ s/[*\$]$// if $right_anchored;
+ $value = quotemeta($value);
$value = '^' . $value if $left_anchored eq '^';
$value = "$value\$" if $right_anchored eq '$';
$value = '[[:<:]]' . $value if $left_wb && !$left_anchored;
SELECT NULL,NULL,NULL,COUNT(*),COUNT(*),COUNT(*),0,0,NULL,NULL FROM w;
SQL
+open SQLTXT, ">", "/tmp/sql.txt";
+print SQLTXT $sql;
+close SQLTXT;
+
warn $sql if $self->QueryParser->debug;
return $sql;
$where .= "$NOT(" . $talias . ".id IS NOT NULL";
if (@{$node->phrases}) {
$where .= ' AND ' . join(' AND ', map {
- "${talias}.value ~* search_normalize(".$self->QueryParser->quote_phrase_value($_, 1).")"
+ "${talias}.value ~* xml_encode_special_chars(search_normalize(".$self->QueryParser->quote_phrase_value($_, 1)."))"
} @{$node->phrases});
- } else {
+ } elsif (((@{$node->only_real_atoms}[0])->{content}) =~ /^\^/) { # matches exactly
+ $where .= " AND ${talias}.value ilike xml_encode_special_chars(search_normalize(";
+ my $phrase_list;
for my $atom (@{$node->only_real_atoms}) {
- next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/;
- $where .= " AND ${talias}.value ~* search_normalize(".$self->QueryParser->quote_phrase_value($atom->{content}).")";
+# my $content = $atom->{content};
+ my $content = ref($atom) ? $atom->{content} : $atom;
+ $content =~ s/^\^//;
+ $content =~ s/\$$//;
+ $phrase_list .= "$content ";
+# next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/;
+# $where .= " AND ${talias}.value ~* search_normalize(".$self->QueryParser->quote_phrase_value($atom->{content}).")";
}
+ $where .= $self->QueryParser->quote_phrase_value($phrase_list).'))';
}
$where .= ')';
#-------------------------------
package OpenILS::Application::Storage::Driver::Pg::QueryParser::query_plan::node;
+use OpenILS::Application::Storage::QueryParser;
use base 'QueryParser::query_plan::node';
use List::MoreUtils qw/uniq/;
use Data::Dumper;
+use OpenSRF::Utils::Logger qw($logger);
+
sub abstract_node_additions {
my $self = shift;
my $atoms = $self->query_atoms;
my @only_real_atoms;
for my $a (@$atoms) {
- push(@only_real_atoms, $a) if (ref($a) && $a->isa('QueryParser::query_plan::node::atom') && !($a->{dummy}));
+ push(@only_real_atoms, $a) if ((ref($a) && $a->isa('QueryParser::query_plan::node::atom') && !($a->{dummy})) ||
+ $self->plan->QueryParser->query =~ '^.*&.*$');
}
-
return \@only_real_atoms;
}