2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
7 # <jesse@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/copyleft/gpl.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
57 Use the argument passed in as a "Google-style" set of keywords
64 ok (require RT::Search::Generic);
71 package RT::Search::Googleish;
74 use base qw(RT::Search::Generic);
82 $self->{'Queues'} = delete($args{'Queues'}) || [];
83 $self->SUPER::_Init(%args);
90 return ($self->loc("No description for [_1]", ref $self));
97 my $query = shift || $self->Argument;
98 my @keywords = split /\s+/, $query;
100 @tql_clauses, @owner_clauses, @queue_clauses,
101 @user_clauses, @id_clauses, @status_clauses
103 my ( $Queue, $User );
104 for my $key (@keywords) {
106 # Is this a ticket number? If so, go to it.
107 if ( $key =~ m/^\d+$/ ) {
108 push @id_clauses, "id = '$key'";
111 elsif ( $key =~ /\w+\@\w+/ ) {
112 push @user_clauses, "Requestor LIKE '$key'";
115 # Is there a status with this name?
117 $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
118 and $Queue->IsValidStatus($key)
121 push @status_clauses, "Status = '" . $key . "'";
124 # Is there a owner named $key?
125 # Is there a queue named $key?
126 elsif ( $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
127 and $Queue->Load($key) )
129 push @queue_clauses, "Queue = '" . $Queue->Name . "'";
132 # Is there a owner named $key?
133 elsif ( $User = RT::User->new( $self->TicketsObj->CurrentUser )
134 and $User->Load($key)
135 and $User->Privileged )
137 push @owner_clauses, "Owner = '" . $User->Name . "'";
140 elsif ($key =~ /^fulltext:(.*?)$/i) {
142 $key =~ s/['\\].*//g;
143 push @tql_clauses, "Content LIKE '$key'";
147 # Else, subject must contain $key
149 $key =~ s/['\\].*//g;
150 push @tql_clauses, "Subject LIKE '$key'";
154 # restrict to any queues requested by the caller
155 for my $queue (@{ $self->{'Queues'} }) {
156 my $QueueObj = RT::Queue->new($self->TicketsObj->CurrentUser);
157 $QueueObj->Load($queue) or next;
158 push @queue_clauses, "Queue = '" . $QueueObj->Name . "'";
161 push @tql_clauses, join( " OR ", sort @id_clauses );
162 push @tql_clauses, join( " OR ", sort @owner_clauses );
163 push @tql_clauses, join( " OR ", sort @status_clauses );
164 push @tql_clauses, join( " OR ", sort @user_clauses );
165 push @tql_clauses, join( " OR ", sort @queue_clauses );
166 @tql_clauses = grep { $_ ? $_ = "( $_ )" : undef } @tql_clauses;
167 return join " AND ", sort @tql_clauses;
174 my $tql = $self->QueryToSQL($self->Argument);
176 $RT::Logger->crit($tql);
178 $self->TicketsObj->FromSQL($tql);
183 eval "require RT::Search::Googleish_Vendor";
184 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Googleish_Vendor.pm});
185 eval "require RT::Search::Googleish_Local";
186 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Googleish_Local.pm});