1 { # Every driver needs to provide a 'compile()' method to OpenILS::Application::Storage::FTS.
2 # If that driver wants to support FTI, that is...
3 #-------------------------------------------------------------------------------
4 package OpenILS::Application::Storage::FTS;
5 use OpenSRF::Utils::Logger qw/:level/;
6 my $log = 'OpenSRF::Utils::Logger';
12 $self = ref($self) || $self;
13 $self = bless {} => $self;
16 $self->decompose($term);
18 my $newterm = join('&', $self->words);
21 $newterm = '('.$newterm.')&!('. join('|', $self->nots) . ')';
24 $log->debug("Compiled term is [$newterm]", DEBUG);
25 $newterm = OpenILS::Application::Storage::Driver::Pg->quote($newterm);
26 $log->debug("Quoted term is [$newterm]", DEBUG);
28 $self->{fts_query} = ["to_tsquery('default',$newterm)"];
29 $self->{fts_query_nots} = [];
30 $self->{fts_op} = '@@';
31 $self->{text_col} = shift;
32 $self->{fts_col} = shift;
37 sub sql_where_clause {
39 my $column = $self->fts_col;
43 for my $fts ( $self->fts_query ) {
44 push @output, join(' ', $self->fts_col, $self->{fts_op}, $fts);
45 push @ranks, "rank($column, $fts)";
47 $self->{fts_rank} = \@ranks;
49 my $phrase_match = $self->sql_exact_phrase_match();
50 return join(' AND ', @output) . $phrase_match;