[open-ils-commits] r18540 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg (gmc)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 28 21:25:02 EDT 2010


Author: gmc
Date: 2010-10-28 21:25:01 -0400 (Thu, 28 Oct 2010)
New Revision: 18540

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Log:
adjust quoting of phrase searches

This has three main effects:

* This formalizes the current behavior where a
  phrase search like

  title:"^Harry Potter"

  acts as a left-anchored search and
  
  title:"Harry Potter$"

  acts as a right-anchored search.

In particular, this can be useful for constructing
searches of bibliographic call numbers.

* Other regex metacharacters in phrase searches are
  now escaped.

* Phrase searches like "C++" will no longer crash; in fact,
  this makes a phrase search currently the only way to
  accurately retrieve all C++ titles with the usual
  normalization rules

Signed-off-by: Galen Charlton <gmc at esilibrary.com>


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm	2010-10-29 00:06:26 UTC (rev 18539)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm	2010-10-29 01:25:01 UTC (rev 18540)
@@ -17,6 +17,20 @@
     return "\$_$$\$$value\$_$$\$";
 }
 
+sub quote_phrase_value {
+    my $self = shift;
+    my $value = shift;
+
+    my $left_anchored  = $value =~ m/^\^/;
+    my $right_anchored = $value =~ m/\$$/;
+    $value =~ s/\^//   if $left_anchored;
+    $value =~ s/\$$//  if $right_anchored;
+    $value =~ quotemeta($value);
+    $value = '^' . $value if $left_anchored;
+    $value = "$value\$"   if $right_anchored;
+    return $self->quote_value($value);
+}
+
 sub init {
     my $class = shift;
 
@@ -619,7 +633,7 @@
                 }
 
                 $where .= '(' . $talias . ".id IS NOT NULL";
-                $where .= ' AND ' . join(' AND ', map {"${talias}.value ~* ".$self->QueryParser->quote_value($_)} @{$node->phrases}) if (@{$node->phrases});
+                $where .= ' AND ' . join(' AND ', map {"${talias}.value ~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->phrases}) if (@{$node->phrases});
                 $where .= ')';
 
                 push @rank_list, $node_rank;



More information about the open-ils-commits mailing list