kmain-396 exact search modified: usr/lib/perl5/site_perl/5.8.8/OpenILS/Application...
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:07:27 +0000 (17:07 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: 97d8914

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 838679d..3e96a06 100644 (file)
@@ -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;
 }