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);
25 $newterm = join('&', $self->words) if ($self->words);
28 $newterm = '('.$newterm.')&' if ($newterm);
29 $newterm .= '!('. join('|', $self->nots) . ')';
32 $log->debug("Compiled term is [$newterm]", DEBUG);
33 $newterm = OpenILS::Application::Storage::Driver::Pg->quote($newterm);
34 $log->debug("Quoted term is [$newterm]", DEBUG);
36 $self->{fts_query} = ["to_tsquery('default',$newterm)"];
37 $self->{fts_query_nots} = [];
38 $self->{fts_op} = '@@';
39 $self->{text_col} = shift;
40 $self->{fts_col} = shift;
45 sub sql_where_clause {
47 my $column = $self->fts_col;
51 for my $fts ( $self->fts_query ) {
52 push @output, join(' ', $self->fts_col, $self->{fts_op}, $fts);
53 push @ranks, "rank($column, $fts)";
55 $self->{fts_rank} = \@ranks;
57 my $phrase_match = $self->sql_exact_phrase_match();
58 return join(' AND ', @output) . $phrase_match;