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 use Unicode::Normalize;
7 my $log = 'OpenSRF::Utils::Logger';
11 my $term = NFD(shift());
13 $log->debug("Raw term: $term",DEBUG);
18 $self = ref($self) || $self;
19 $self = bless {} => $self;
21 $term =~ s/(\pM+)//gos;
22 $self->decompose($term);
24 my $newterm = join('&', $self->words);
27 $newterm = '('.$newterm.')&!('. join('|', $self->nots) . ')';
30 $log->debug("Compiled term is [$newterm]", DEBUG);
31 $newterm = OpenILS::Application::Storage::Driver::Pg->quote($newterm);
32 $log->debug("Quoted term is [$newterm]", DEBUG);
34 $self->{fts_query} = ["to_tsquery('default',$newterm)"];
35 $self->{fts_query_nots} = [];
36 $self->{fts_op} = '@@';
37 $self->{text_col} = shift;
38 $self->{fts_col} = shift;
43 sub sql_where_clause {
45 my $column = $self->fts_col;
49 for my $fts ( $self->fts_query ) {
50 push @output, join(' ', $self->fts_col, $self->{fts_op}, $fts);
51 push @ranks, "rank($column, $fts)";
53 $self->{fts_rank} = \@ranks;
55 my $phrase_match = $self->sql_exact_phrase_match();
56 return join(' AND ', @output) . $phrase_match;