summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Search
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/Search')
-rw-r--r--rt/lib/RT/Search/ActiveTicketsInQueue.pm12
-rw-r--r--rt/lib/RT/Search/FromSQL.pm12
-rw-r--r--rt/lib/RT/Search/Generic.pm98
-rw-r--r--rt/lib/RT/Search/Googleish.pm51
4 files changed, 56 insertions, 117 deletions
diff --git a/rt/lib/RT/Search/ActiveTicketsInQueue.pm b/rt/lib/RT/Search/ActiveTicketsInQueue.pm
index 3336ed747..f948ad76c 100644
--- a/rt/lib/RT/Search/ActiveTicketsInQueue.pm
+++ b/rt/lib/RT/Search/ActiveTicketsInQueue.pm
@@ -1,8 +1,8 @@
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -45,6 +45,7 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
+
=head1 NAME
RT::Search::ActiveTicketsInQueue
@@ -58,11 +59,6 @@ Find all active tickets in the queue named in the argument passed in
=head1 METHODS
-=begin testing
-
-ok (require RT::Search::Generic);
-
-=end testing
=cut
@@ -70,7 +66,7 @@ ok (require RT::Search::Generic);
package RT::Search::ActiveTicketsInQueue;
use strict;
-use base qw(RT::Search::Generic);
+use base qw(RT::Search);
# {{{ sub Describe
diff --git a/rt/lib/RT/Search/FromSQL.pm b/rt/lib/RT/Search/FromSQL.pm
index 6e4708fd0..3913713a8 100644
--- a/rt/lib/RT/Search/FromSQL.pm
+++ b/rt/lib/RT/Search/FromSQL.pm
@@ -1,8 +1,8 @@
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -45,6 +45,7 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
+
=head1 NAME
RT::Search::FromSQL
@@ -58,11 +59,6 @@ Find all tickets described by the SQL statement passed as an argument
=head1 METHODS
-=begin testing
-
-ok (require RT::Search::Generic);
-
-=end testing
=cut
@@ -70,7 +66,7 @@ ok (require RT::Search::Generic);
package RT::Search::FromSQL;
use strict;
-use base qw(RT::Search::Generic);
+use base qw(RT::Search);
=head2 Describe
diff --git a/rt/lib/RT/Search/Generic.pm b/rt/lib/RT/Search/Generic.pm
index 68940deb8..c36cdb15a 100644
--- a/rt/lib/RT/Search/Generic.pm
+++ b/rt/lib/RT/Search/Generic.pm
@@ -1,8 +1,8 @@
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -45,108 +45,36 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
+
=head1 NAME
- RT::Search::Generic - ;
+ RT::Search::Generic - deprecated, see RT::Search
=head1 SYNOPSIS
- use RT::Search::Generic;
- my $tickets = RT::Tickets->new($CurrentUser);
- my $foo = RT::Search::Generic->new(Argument => $arg,
- TicketsObj => $tickets);
- $foo->Prepare();
- while ( my $ticket = $foo->Next ) {
- # Do something with each ticket we've found
- }
-
+ use RT::Search::Generic;
=head1 DESCRIPTION
+This module is provided only for backwards compatibility.
=head1 METHODS
-=begin testing
-
-ok (require RT::Search::Generic);
-
-=end testing
-
-
=cut
-package RT::Search::Generic;
-
use strict;
-
-# {{{ sub new
-sub new {
- my $proto = shift;
- my $class = ref($proto) || $proto;
- my $self = {};
- bless ($self, $class);
- $self->_Init(@_);
- return $self;
-}
-# }}}
-
-# {{{ sub _Init
-sub _Init {
- my $self = shift;
- my %args = (
- TicketsObj => undef,
- Argument => undef,
- @_ );
-
- $self->{'TicketsObj'} = $args{'TicketsObj'};
- $self->{'Argument'} = $args{'Argument'};
-}
-# }}}
-
-# {{{ sub Argument
-
-=head2 Argument
-
-Return the optional argument associated with this Search
-
-=cut
-
-sub Argument {
- my $self = shift;
- return($self->{'Argument'});
-}
-# }}}
-
-
-=head2 TicketsObj
-
-Return the Tickets object passed into this search
-
-=cut
-
-sub TicketsObj {
- my $self = shift;
- return($self->{'TicketsObj'});
-}
-
-# {{{ sub Describe
-sub Describe {
- my $self = shift;
- return ($self->loc("No description for [_1]", ref $self));
-}
-# }}}
-
-# {{{ sub Prepare
-sub Prepare {
- my $self = shift;
- return(1);
-}
-# }}}
+use warnings;
+package RT::Search::Generic;
+use base 'RT::Search';
eval "require RT::Search::Generic_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Generic_Vendor.pm});
+warn "RT::Search::Generic has become RT::Search. Please adjust your RT::Search::Generic_Vendor file at " . $INC{"RT/Search/Generic_Vendor.pm"} if !$@;
+
eval "require RT::Search::Generic_Local";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Generic_Local.pm});
+warn "RT::Search::Generic has become RT::Search. Please adjust your RT::Search::Generic_Local file at " . $INC{"RT/Search/Generic_Local.pm"} if !$@;
1;
+
diff --git a/rt/lib/RT/Search/Googleish.pm b/rt/lib/RT/Search/Googleish.pm
index c784b1b9c..07e1904b1 100644
--- a/rt/lib/RT/Search/Googleish.pm
+++ b/rt/lib/RT/Search/Googleish.pm
@@ -2,8 +2,8 @@
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -46,6 +46,7 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
+
=head1 NAME
RT::Search::Googlish
@@ -59,11 +60,6 @@ Use the argument passed in as a "Google-style" set of keywords
=head1 METHODS
-=begin testing
-
-ok (require RT::Search::Generic);
-
-=end testing
=cut
@@ -71,8 +67,11 @@ ok (require RT::Search::Generic);
package RT::Search::Googleish;
use strict;
-use base qw(RT::Search::Generic);
+use warnings;
+use base qw(RT::Search);
+use Regexp::Common qw/delimited/;
+my $re_delim = qr[$RE{delimited}{-delim=>qq{\'\"}}];
# sub _Init {{{
sub _Init {
@@ -95,7 +94,10 @@ sub Describe {
sub QueryToSQL {
my $self = shift;
my $query = shift || $self->Argument;
- my @keywords = split /\s+/, $query;
+
+ my @keywords = grep length, map { s/^\s+//; s/\s+$//; $_ }
+ split /((?:fulltext:)?$re_delim|\s+)/o, $query;
+
my (
@tql_clauses, @owner_clauses, @queue_clauses,
@user_clauses, @id_clauses, @status_clauses
@@ -104,11 +106,21 @@ sub QueryToSQL {
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'";
@@ -128,12 +140,13 @@ sub QueryToSQL {
push @status_clauses, "Status = '" . $key . "'";
}
- # Is there a owner named $key?
# Is there a queue named $key?
elsif ( $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
and $Queue->Load($key) )
{
- push @queue_clauses, "Queue = '" . $Queue->Name . "'";
+ my $quoted_queue = $Queue->Name;
+ $quoted_queue =~ s/'/\\'/g;
+ push @queue_clauses, "Queue = '$quoted_queue'";
}
# Is there a owner named $key?
@@ -155,12 +168,18 @@ sub QueryToSQL {
for my $queue (@{ $self->{'Queues'} }) {
my $QueueObj = RT::Queue->new($self->TicketsObj->CurrentUser);
$QueueObj->Load($queue) or next;
- push @queue_clauses, "Queue = '" . $QueueObj->Name . "'";
+ my $quoted_queue = $QueueObj->Name;
+ $quoted_queue =~ s/'/\\'/g;
+ push @queue_clauses, "Queue = '$quoted_queue'";
}
push @tql_clauses, join( " OR ", sort @id_clauses );
push @tql_clauses, join( " OR ", sort @owner_clauses );
- push @tql_clauses, join( " OR ", sort @status_clauses );
+ if ( ! @status_clauses ) {
+ push @tql_clauses, join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray());
+ } else {
+ push @tql_clauses, join( " OR ", sort @status_clauses );
+ }
push @tql_clauses, join( " OR ", sort @user_clauses );
push @tql_clauses, join( " OR ", sort @queue_clauses );
@tql_clauses = grep { $_ ? $_ = "( $_ )" : undef } @tql_clauses;
@@ -173,7 +192,7 @@ sub Prepare {
my $self = shift;
my $tql = $self->QueryToSQL($self->Argument);
- $RT::Logger->crit($tql);
+ $RT::Logger->debug($tql);
$self->TicketsObj->FromSQL($tql);
return(1);