]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/fts.pm
stripping combining chars for searching
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Driver / Pg / fts.pm
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';
7
8         sub compile {
9                 my $self = shift;
10                 my $term = shift;
11
12                 $self = ref($self) || $self;
13                 $self = bless {} => $self;
14
15                 $term =~ s/\pM//gos;
16                 $self->decompose($term);
17
18                 my $newterm = join('&', $self->words);
19
20                 if (@{$self->nots}) {
21                         $newterm = '('.$newterm.')&!('. join('|', $self->nots) . ')';
22                 }
23
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);
27
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;
33
34                 return $self;
35         }
36
37         sub sql_where_clause {
38                 my $self = shift;
39                 my $column = $self->fts_col;
40                 my @output;
41         
42                 my @ranks;
43                 for my $fts ( $self->fts_query ) {
44                         push @output, join(' ', $self->fts_col, $self->{fts_op}, $fts);
45                         push @ranks, "rank($column, $fts)";
46                 }
47                 $self->{fts_rank} = \@ranks;
48         
49                 my $phrase_match = $self->sql_exact_phrase_match();
50                 return join(' AND ', @output) . $phrase_match;
51         }
52
53 }
54
55 1;