[Rt-commit] r18612 - rt/3.8/trunk/lib/RT/Search

ruz at bestpractical.com ruz at bestpractical.com
Mon Mar 2 12:02:09 EST 2009


Author: ruz
Date: Mon Mar  2 12:02:05 2009
New Revision: 18612

Modified:
   rt/3.8/trunk/lib/RT/Search/Googleish.pm

Log:
* add support for quoting in simple search to allow search
  for numbers, strings with spaces in subject or content

Modified: rt/3.8/trunk/lib/RT/Search/Googleish.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Search/Googleish.pm	(original)
+++ rt/3.8/trunk/lib/RT/Search/Googleish.pm	Mon Mar  2 12:02:05 2009
@@ -67,8 +67,11 @@
 package RT::Search::Googleish;
 
 use strict;
+use warnings;
 use base qw(RT::Search);
 
+use Regexp::Common qw/delimited/;
+my $re_delim = qr[$RE{delimited}{-delim=>qq{\'\"}}];
 
 # sub _Init {{{
 sub _Init {
@@ -91,9 +94,10 @@
 sub QueryToSQL {
     my $self     = shift;
     my $query    = shift || $self->Argument;
-    # Trim leading or trailing whitespace
-    $query =~ s/^\s+(.*)\s+$/$1/g;
-    my @keywords = split /\s+/, $query;
+
+    my @keywords = grep length, map { s/^\s+//; s/\s+$//; $_ }
+        split /((?:fultext:)?$re_delim|\s+)/o, $query;
+
     my (
         @tql_clauses,  @owner_clauses, @queue_clauses,
         @user_clauses, @id_clauses,    @status_clauses
@@ -102,11 +106,21 @@
     for my $key (@keywords) {
 
         # Is this a ticket number? If so, go to it.
+        # But look into subject as well
         if ( $key =~ m/^\d+$/ ) {
-            push @id_clauses, "id = '$key'";
+            push @id_clauses, "id = '$key'", "Subject LIKE '$key'";
+        }
+
+        # if it's quoted string then search it "as is" in subject or fulltext
+        elsif ( $key =~ /^(fulltext:)?($re_delim)$/io ) {
+            if ( $1 ) {
+                push @tql_clauses, "Content LIKE $2";
+            } else {
+                push @tql_clauses, "Subject LIKE $2";
+            }
         }
 
-        elsif ($key =~ /^fulltext:(.*?)$/i) {
+        elsif ( $key =~ /^fulltext:(.*?)$/i ) {
             $key = $1;
             $key =~ s/['\\].*//g;
             push @tql_clauses, "Content LIKE '$key'";


More information about the Rt-commit mailing list