[Rt-commit] rt branch, googleish-refactor, updated. rt-3.9.4-466-g57c6de4

Alex Vandiver alexmv at bestpractical.com
Wed Nov 17 16:32:34 EST 2010


The branch, googleish-refactor has been updated
       via  57c6de4ae6d566991ad777efa21b9feef2ebe03c (commit)
       via  8a302ce136c78c974fdf28408baa29401c53d466 (commit)
      from  48698247204eef26124e432c8277329fa9bdf37d (commit)

Summary of changes:
 lib/RT/Search/Googleish.pm |   15 ++++++++++++---
 t/web/googleish_search.t   |    9 ++++++++-
 2 files changed, 20 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit 8a302ce136c78c974fdf28408baa29401c53d466
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Nov 17 16:29:53 2010 -0500

    Allow googlish handlers to return a list of limits to push

diff --git a/lib/RT/Search/Googleish.pm b/lib/RT/Search/Googleish.pm
index f8ca0bd..e550843 100644
--- a/lib/RT/Search/Googleish.pm
+++ b/lib/RT/Search/Googleish.pm
@@ -148,8 +148,8 @@ sub Dispatch {
 
     my $method = "Handle" . ucfirst(lc($type));
     $method = "HandleDefault" unless $self->can($method);
-    my ($key, $tsql) = $self->$method($contents, $quoted, $extra);
-    push @{$limits->{$key}}, $tsql;
+    my ($key, @tsql) = $self->$method($contents, $quoted, $extra);
+    push @{$limits->{$key}}, @tsql;
 }
 
 sub Unquote {

commit 57c6de4ae6d566991ad777efa21b9feef2ebe03c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Nov 17 16:32:18 2010 -0500

    Allow searching for active or inactive tickets using [active] or [status:active]

diff --git a/lib/RT/Search/Googleish.pm b/lib/RT/Search/Googleish.pm
index e550843..6356059 100644
--- a/lib/RT/Search/Googleish.pm
+++ b/lib/RT/Search/Googleish.pm
@@ -198,6 +198,7 @@ our @GUESS = (
     [ 40 => sub {
           return "status" if RT::Queue->new( $_[2] )->IsValidStatus( $_ )
       }],
+    [ 40 => sub { return "status" if /^(in)?active$/i } ],
     [ 50 => sub {
           my $q = RT::Queue->new( $_[2] );
           return "queue" if $q->Load($_) and $q->Id
@@ -227,7 +228,15 @@ sub HandleSubject   { return subject   => "Subject LIKE '$_[1]'"; }
 sub HandleFulltext  { return content   => "Content LIKE '$_[1]'"; }
 sub HandleContent   { return content   => "Content LIKE '$_[1]'"; }
 sub HandleId        { $_[1] =~ s/^#//; return id => "Id = $_[1]"; }
-sub HandleStatus    { return status    => "Status = '$_[1]'";     }
+sub HandleStatus    {
+    if ($_[1] =~ /^active$/i and !$_[2]) {
+        return status => map {s/(['\\])/\\$1/g; "Status = '$_'"} RT::Queue->ActiveStatusArray();
+    } elsif ($_[1] =~ /^inactive$/i and !$_[2]) {
+        return status => map {s/(['\\])/\\$1/g; "Status = '$_'"} RT::Queue->InactiveStatusArray();
+    } else {
+        return status => "Status = '$_[1]'";
+    }
+}
 sub HandleOwner     {
     return owner  => (!$_[2] and $_[1] eq "me") ? "Owner.id = '__CurrentUser__'" : "Owner = '$_[1]'";
 }
diff --git a/t/web/googleish_search.t b/t/web/googleish_search.t
index ad37755..1fce804 100644
--- a/t/web/googleish_search.t
+++ b/t/web/googleish_search.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 79, config => 'Set( %FullTextSearch, Enable => 1, Indexed => 0 );';
+use RT::Test tests => 84, config => 'Set( %FullTextSearch, Enable => 1, Indexed => 0 );';
 my ($baseurl, $m) = RT::Test->started_ok;
 my $url = $m->rt_base_url;
 
@@ -19,6 +19,7 @@ ok $two_words_queue && $two_words_queue->id, 'loaded or created a queue';
 {
     my $tickets = RT::Tickets->new( RT->SystemUser );
     my $active = "( ".join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray())." )";
+    my $inactive = "( ".join( " OR ", map "Status = '$_'", RT::Queue->InactiveStatusArray())." )";
 
     require RT::Search::Googleish;
     my $parser = RT::Search::Googleish->new(
@@ -56,6 +57,12 @@ ok $two_words_queue && $two_words_queue->id, 'loaded or created a queue';
     is $parser->QueryToSQL("'me'"), "$active AND ( Subject LIKE 'me' )", "correct parsing";
     is $parser->QueryToSQL("owner:me"), "( Owner.id = '__CurrentUser__' ) AND $active", "correct parsing";
     is $parser->QueryToSQL("owner:'me'"), "( Owner = 'me' ) AND $active", "correct parsing";
+
+    is $parser->QueryToSQL("resolved me"), "( Owner.id = '__CurrentUser__' ) AND ( Status = 'resolved' )", "correct parsing";
+    is $parser->QueryToSQL("resolved active me"), "( Owner.id = '__CurrentUser__' ) AND ( Status = 'resolved' OR Status = 'new' OR Status = 'open' OR Status = 'stalled' )", "correct parsing";
+    is $parser->QueryToSQL("status:active"), $active, "Explicit active search";
+    is $parser->QueryToSQL("status:'active'"), "( Status = 'active' )", "Quoting active makes it the actual word";
+    is $parser->QueryToSQL("inactive me"), "( Owner.id = '__CurrentUser__' ) AND $inactive", "correct parsing";
 }
 
 my $ticket_found_1 = RT::Ticket->new($RT::SystemUser);

-----------------------------------------------------------------------


More information about the Rt-commit mailing list