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);
80 return ($self->loc("No description for [_1]", ref $self));
87 my $query = shift || $self->Argument;
88 my @keywords = split /\s+/, $query;
90 @tql_clauses, @owner_clauses, @queue_clauses,
91 @user_clauses, @id_clauses, @status_clauses
94 for my $key (@keywords) {
96 # Is this a ticket number? If so, go to it.
97 if ( $key =~ m/^\d+$/ ) {
98 push @id_clauses, "id = '$key'";
101 elsif ( $key =~ /\w+\@\w+/ ) {
102 push @user_clauses, "Requestor LIKE '$key'";
105 # Is there a status with this name?
107 $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
108 and $Queue->IsValidStatus($key)
111 push @status_clauses, "Status = '" . $key . "'";
114 # Is there a owner named $key?
115 # Is there a queue named $key?
116 elsif ( $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
117 and $Queue->Load($key) )
119 push @queue_clauses, "Queue = '" . $Queue->Name . "'";
122 # Is there a owner named $key?
123 elsif ( $User = RT::User->new( $self->TicketsObj->CurrentUser )
124 and $User->Load($key)
125 and $User->Privileged )
127 push @owner_clauses, "Owner = '" . $User->Name . "'";
130 elsif ($key =~ /^fulltext:(.*?)$/i) {
132 $key =~ s/['\\].*//g;
133 push @tql_clauses, "Content LIKE '$key'";
137 # Else, subject must contain $key
139 $key =~ s/['\\].*//g;
140 push @tql_clauses, "Subject LIKE '$key'";
144 push @tql_clauses, join( " OR ", sort @id_clauses );
145 push @tql_clauses, join( " OR ", sort @owner_clauses );
146 push @tql_clauses, join( " OR ", sort @status_clauses );
147 push @tql_clauses, join( " OR ", sort @user_clauses );
148 push @tql_clauses, join( " OR ", sort @queue_clauses );
149 @tql_clauses = grep { $_ ? $_ = "( $_ )" : undef } @tql_clauses;
150 return join " AND ", sort @tql_clauses;
157 my $tql = $self->QueryToSQL($self->Argument);
159 $RT::Logger->crit($tql);
161 $self->TicketsObj->FromSQL($tql);
166 eval "require RT::Search::Googleish_Vendor";
167 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Googleish_Vendor.pm});
168 eval "require RT::Search::Googleish_Local";
169 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Googleish_Local.pm});