5 use RT::Test tests => undef;
6 plan skip_all => 'Not Pg' unless RT->Config->Get('DatabaseType') eq 'Pg';
8 my ($major, $minor) = $RT::Handle->dbh->get_info(18) =~ /^0*(\d+)\.0*(\d+)/;
9 plan skip_all => "Need Pg 8.2 or higher; we have $major.$minor"
10 if "$major.$minor" < 8.2;
14 RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, Column => 'ContentIndex', Table => 'Attachments' );
18 my $q = RT::Test->load_or_create_queue( Name => 'General' );
19 ok $q && $q->id, 'loaded or created queue';
25 command => $RT::SbinPath .'/rt-setup-fulltext-index',
26 dba => $ENV{'RT_DBA_USER'},
27 'dba-password' => $ENV{'RT_DBA_PASSWORD'},
29 my ($exit_code, $output) = RT::Test->run_and_capture( %args );
30 ok(!$exit_code, "setted up index") or diag "output: $output";
35 command => $RT::SbinPath .'/rt-fulltext-indexer',
37 my ($exit_code, $output) = RT::Test->run_and_capture( %args );
38 ok(!$exit_code, "setted up index") or diag "output: $output";
43 while ( my ($query, $checks) = splice @test, 0, 2 ) {
44 run_test( $query, %$checks );
50 my ($query, %checks) = @_;
51 my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
53 my $tix = RT::Tickets->new(RT->SystemUser);
54 $tix->FromSQL( "( $query_prefix ) AND ( $query )" );
59 $count++ foreach grep $_, values %checks;
60 is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1;
62 my $good_tickets = ($tix->Count == $count);
63 while ( my $ticket = $tix->Next ) {
64 next if $checks{ $ticket->id };
65 diag $ticket->Subject ." ticket has been found when it's not expected";
68 ok( $good_tickets, "all tickets are good with '$query'" ) or $error = 1;
70 diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
73 @tickets = RT::Test->create_tickets(
75 { Subject => 'fts test 1', Content => 'book' },
76 { Subject => 'fts test 2', Content => 'bars' },
80 my $book = $tickets[0];
81 my $bars = $tickets[1];
84 "Content LIKE 'book'" => { $book->id => 1, $bars->id => 0 },
85 "Content LIKE 'bars'" => { $book->id => 0, $bars->id => 1 },
87 # make sure that Pg stemming works
88 "Content LIKE 'books'" => { $book->id => 1, $bars->id => 0 },
89 "Content LIKE 'bar'" => { $book->id => 0, $bars->id => 1 },
92 "Content LIKE 'baby'" => { $book->id => 0, $bars->id => 0 },
93 "Content LIKE 'pubs'" => { $book->id => 0, $bars->id => 0 },
96 # Test the "ts_vector too long" skip
98 $content .= "$_\n" for 1..200_000;
99 @tickets = RT::Test->create_tickets(
101 { Subject => 'Short content', Content => '50' },
102 { Subject => 'Long content', Content => $content },
103 { Subject => 'More short', Content => '50' },
106 my ($exit_code, $output) = RT::Test->run_and_capture(
107 command => $RT::SbinPath .'/rt-fulltext-indexer'
109 like($output, qr/string is too long for tsvector/, "Got a warning for the ticket");
110 ok(!$exit_code, "set up index");
112 # The long content is skipped entirely
114 "Content LIKE '1'" => { $tickets[0]->id => 0, $tickets[1]->id => 0, $tickets[2]->id => 0 },
115 "Content LIKE '50'" => { $tickets[0]->id => 1, $tickets[1]->id => 0, $tickets[2]->id => 1 },