6 use RT::Test tests => undef;
7 plan skip_all => 'Not Pg' unless RT->Config->Get('DatabaseType') eq 'Pg';
9 my ($major, $minor) = $RT::Handle->dbh->get_info(18) =~ /^0*(\d+)\.0*(\d+)/;
10 plan skip_all => "Need Pg 8.2 or higher; we have $major.$minor"
11 if "$major.$minor" < 8.2;
15 RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, Column => 'ContentIndex', Table => 'Attachments' );
19 my $q = RT::Test->load_or_create_queue( Name => 'General' );
20 ok $q && $q->id, 'loaded or created queue';
26 command => $RT::SbinPath .'/rt-setup-fulltext-index',
27 dba => $ENV{'RT_DBA_USER'},
28 'dba-password' => $ENV{'RT_DBA_PASSWORD'},
30 my ($exit_code, $output) = RT::Test->run_and_capture( %args );
31 ok(!$exit_code, "setted up index") or diag "output: $output";
36 command => $RT::SbinPath .'/rt-fulltext-indexer',
38 my ($exit_code, $output) = RT::Test->run_and_capture( %args );
39 ok(!$exit_code, "setted up index") or diag "output: $output";
44 while ( my ($query, $checks) = splice @test, 0, 2 ) {
45 run_test( $query, %$checks );
51 my ($query, %checks) = @_;
52 my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
54 my $tix = RT::Tickets->new(RT->SystemUser);
55 $tix->FromSQL( "( $query_prefix ) AND ( $query )" );
60 $count++ foreach grep $_, values %checks;
61 is($tix->Count, $count, "found correct number of ticket(s) by '$query'") or $error = 1;
63 my $good_tickets = ($tix->Count == $count);
64 while ( my $ticket = $tix->Next ) {
65 next if $checks{ $ticket->id };
66 diag $ticket->Subject ." ticket has been found when it's not expected";
69 ok( $good_tickets, "all tickets are good with '$query'" ) or $error = 1;
71 diag "Wrong SQL query for '$query':". $tix->BuildSelectQuery if $error;
74 @tickets = RT::Test->create_tickets(
76 { Subject => 'fts test 1', Content => 'book' },
77 { Subject => 'fts test 2', Content => 'bars' },
81 my $book = $tickets[0];
82 my $bars = $tickets[1];
85 "Content LIKE 'book'" => { $book->id => 1, $bars->id => 0 },
86 "Content LIKE 'bars'" => { $book->id => 0, $bars->id => 1 },
88 # make sure that Pg stemming works
89 "Content LIKE 'books'" => { $book->id => 1, $bars->id => 0 },
90 "Content LIKE 'bar'" => { $book->id => 0, $bars->id => 1 },
93 "Content LIKE 'baby'" => { $book->id => 0, $bars->id => 0 },
94 "Content LIKE 'pubs'" => { $book->id => 0, $bars->id => 0 },
97 # Test the "ts_vector too long" skip
99 $content .= "$_\n" for 1..200_000;
100 @tickets = RT::Test->create_tickets(
102 { Subject => 'Short content', Content => '50' },
103 { Subject => 'Long content', Content => $content },
104 { Subject => 'More short', Content => '50' },
107 my ($exit_code, $output) = RT::Test->run_and_capture(
108 command => $RT::SbinPath .'/rt-fulltext-indexer'
110 like($output, qr/string is too long for tsvector/, "Got a warning for the ticket");
111 ok(!$exit_code, "set up index");
113 # The long content is skipped entirely
115 "Content LIKE '1'" => { $tickets[0]->id => 0, $tickets[1]->id => 0, $tickets[2]->id => 0 },
116 "Content LIKE '50'" => { $tickets[0]->id => 1, $tickets[1]->id => 0, $tickets[2]->id => 1 },