From 1e86b5b1a94793aa22884f1e48bac1b393cbdac8 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 29 Oct 2014 17:07:27 -0400 Subject: [PATCH] kmain-396 exact search modified: usr/lib/perl5/site_perl/5.8.8/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm (cherry picked from commit f56f3d61499fc8beac376256117bf22eb9adefc1) Cross-port: 97d8914 Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm --- .../Application/Storage/Driver/Pg/QueryParser.pm | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 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 838679da58..3e96a06e49 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 @@ -11,7 +11,6 @@ use OpenILS::Utils::CStoreEditor; 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 { @@ -85,7 +84,7 @@ sub quote_phrase_value { my $self = shift; my $value = shift; my $wb = shift; - + my $left_anchored = ''; my $right_anchored = ''; my $left_wb = 0; @@ -101,6 +100,7 @@ sub quote_phrase_value { $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; @@ -1174,6 +1174,10 @@ SELECT id, 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; @@ -1352,13 +1356,21 @@ sub flatten { $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 .= ')'; @@ -1892,9 +1904,12 @@ sub buildSQL { #------------------------------- 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; @@ -1995,9 +2010,9 @@ sub only_real_atoms { 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; } -- 2.11.0