1 package OpenILS::Application::Storage::Publisher::authority;
2 use base qw/OpenILS::Application::Storage::Publisher/;
4 use OpenSRF::EX qw/:try/;
5 use OpenILS::Application::Storage::FTS;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::Logger qw/:level/;
8 use OpenSRF::Utils::Cache;
10 use Digest::MD5 qw/md5_hex/;
13 my $log = 'OpenSRF::Utils::Logger';
17 my $parser = XML::LibXML->new;
19 sub find_authority_marc {
24 my $term = $args{term};
26 my $subfield = $args{subfield};
28 my $tag_where = "AND f.tag LIKE '$tag'";
30 $tag_where = "AND f.tag IN ('".join("','",@$tag)."')";
33 my $sf_where = "AND f.subfield = '$subfield'";
35 $sf_where = "AND f.subfield IN ('".join("','",@$subfield)."')";
38 my $search_table = authority::full_rec->table;
39 my $marc_table = authority::record_entry->table;
41 my ($index_col) = authority::full_rec->columns('FTS');
42 $index_col ||= 'value';
44 my $fts = OpenILS::Application::Storage::FTS->compile($term, 'f.value', "f.$index_col");
46 my $fts_where = $fts->sql_where_clause;
47 my $fts_words = join '%', $fts->words;
48 my $fts_words_where = "f.value LIKE '$fts_words\%'";
51 my $select = <<" SQL";
52 SELECT DISTINCT a.marc
56 -- AND $fts_words_where
62 $log->debug("Authority Search SQL :: [$select]",DEBUG);
64 my $recs = authority::full_rec->db_Main->selectcol_arrayref( $select );
66 $log->debug("Search yielded ".scalar(@$recs)." results.",DEBUG);
68 $client->respond($_) for (@$recs);
71 __PACKAGE__->register_method(
72 api_name => "open-ils.storage.authority.search.marc",
73 method => 'find_authority_marc',
81 my $class = shift || 'metabib::full_rec';
83 my $table = $class->table;
85 my ($index_col) = $class->columns('FTS');
86 $index_col ||= 'value';
88 my $fts = OpenILS::Application::Storage::FTS->compile($term, 'm.value', "m.$index_col");
89 my $fts_where = $fts->sql_where_clause;
98 return $class->db_Main->selectcol_arrayref($sql)->[0];
101 sub find_see_from_controlled {
106 (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o;
108 $sf = 't' if ($class eq 'title');
110 my @marc = $self->method_lookup('open-ils.storage.authority.search.marc')
111 ->run( term => $term, tag => '4%', subfield => $sf );
112 for my $m ( @marc ) {
113 my $doc = $parser->parse_string($m);
114 my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*[@code="a" or @code="d" or @code="x"]');
115 my $list = [ map { $_->textContent } @nodes ];
116 $client->respond( $list ) if (_empty_check(join(' ',@$list), "metabib::${class}_field_entry"));
120 for my $class ( qw/title author subject keyword series/ ) {
121 __PACKAGE__->register_method(
122 api_name => "open-ils.storage.authority.$class.see_from.controlled",
123 method => 'find_see_from_controlled',
130 sub find_see_also_from_controlled {
135 (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o;
137 $sf = 't' if ($class eq 'title');
139 my @marc = $self->method_lookup('open-ils.storage.authority.search.marc')
140 ->run( term => $term, tag => '5%', subfield => $sf );
141 for my $m ( @marc ) {
142 my $doc = $parser->parse_string($m);
143 my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*[@code="a" or @code="d" or @code="x"]');
144 my $list = [ map { $_->textContent } @nodes ];
145 $client->respond( $list ) if (_empty_check(join(' ',@$list), "metabib::${class}_field_entry"));
149 for my $class ( qw/title author subject keyword series/ ) {
150 __PACKAGE__->register_method(
151 api_name => "open-ils.storage.authority.$class.see_also_from.controlled",
152 method => 'find_see_also_from_controlled',