]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
tons of storage server changes... see diffs
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / metabib.pm
1 package OpenILS::Application::Storage::Publisher::metabib;
2 use base qw/OpenILS::Application::Storage/;
3 use vars qw/$VERSION/;
4 use OpenSRF::EX qw/:try/;
5 use OpenILS::Application::Storage::CDBI::metabib;
6 use OpenILS::Application::Storage::FTS;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenSRF::Utils::Logger;
9
10 my $log = 'OpenSRF::Utils::Logger';
11
12 $VERSION = 1;
13
14
15 sub search_full_rec {
16         my $self = shift;
17         my $client = shift;
18         my $limiters = shift;
19         my $term = shift;
20
21         my ($fts_col) = metabib::full_rec->columns('FTS');
22         my $table = metabib::full_rec->table;
23
24         my $fts = OpenILS::Application::Storage::FTS->compile($term, 'value','index_vector');
25
26         my $fts_where = $fts->sql_where_clause();
27         my @fts_ranks = $fts->fts_rank;
28
29         my $rank = join(' + ', @fts_ranks);
30
31         my @binds;
32         my @wheres;
33         for my $limit (@$limiters) {
34                 push @wheres, "( tag = ? AND subfield LIKE ? AND $fts_where )";
35                 push @binds, $$limit{tag}, $$limit{subfield};
36                 $log->debug("Limiting query using { tag => $$limit{tag}, subfield => $$limit{subfield} }", DEBUG);
37         }
38         my $where = join(' OR ', @wheres);
39
40         my $select = "SELECT record, sum($rank) FROM $table WHERE $where GROUP BY 1 ORDER BY 2 DESC;";
41
42         $log->debug("Search SQL :: [$select]",DEBUG);
43
44         my $recs = metabib::full_rec->db_Main->selectall_arrayref($select, {}, @binds);
45         $log->debug("Search yielded ".scalar(@$recs)." results.",DEBUG);
46         return $recs;
47
48 }
49 __PACKAGE__->register_method(
50         api_name        => 'open-ils.storage.direct.metabib.full_rec.search_fts.value',
51         method          => 'search_full_rec',
52         api_level       => 1,
53         stream          => 1,
54 );
55 __PACKAGE__->register_method(
56         api_name        => 'open-ils.storage.direct.metabib.full_rec.search_fts.index_vector',
57         method          => 'search_full_rec',
58         api_level       => 1,
59         stream          => 1,
60 );
61
62
63 1;