adding open-ils.search support from subject crossreferencing
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Nov 2005 17:55:47 +0000 (17:55 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Nov 2005 17:55:47 +0000 (17:55 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1996 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm [new file with mode: 0644]
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm

index 7d187f5..6284c2e 100644 (file)
@@ -11,6 +11,7 @@ use OpenSRF::Utils::Cache;
 
 #use OpenILS::Application::Search::StaffClient;
 use OpenILS::Application::Search::Biblio;
+use OpenILS::Application::Search::Authority;
 use OpenILS::Application::Search::Actor;
 use OpenILS::Application::Search::Z3950;
 
diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm
new file mode 100644 (file)
index 0000000..94a6899
--- /dev/null
@@ -0,0 +1,42 @@
+package OpenILS::Application::Search::Authority;
+use base qw/OpenSRF::Application/;
+use strict; use warnings;
+
+use OpenILS::EX;
+
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Application::AppUtils;
+
+use JSON;
+
+use Time::HiRes qw(time);
+use OpenSRF::EX qw(:try);
+use Digest::MD5 qw(md5_hex);
+
+sub crossref_subject {
+       my $self = shift;
+       my $client = shift;
+       my $subject = shift;
+
+       my $session = OpenSRF::AppSession->create("open-ils.storage");
+       $session->connect;
+
+       my $freq = $session->request('open-ils.storage.authority.subject.see_from.controlled.atomic',$subject);
+       my $areq = $session->request('open-ils.storage.authority.subject.see_also_from.controlled.atomic',$subject);
+
+       my $from = $freq->gather(1);
+       my $also = $areq->gather(1);
+
+       $session->disconnect;
+
+       return { from => $from, also => $also };
+}
+__PACKAGE__->register_method(
+        method         => "crossref_subject",
+        api_name       => "open-ils.search.authority.subject.crossref",
+        argc           => 1, 
+        note           => "Searches authority data for existing subject controlled terms and crossrefs",
+);              
+
+
+1;
index 08351c6..8638054 100644 (file)
@@ -96,46 +96,54 @@ sub find_see_from_controlled {
        my $client = shift;
        my $term = shift;
 
+       (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o;
+
        my @marc = $self->method_lookup('open-ils.storage.authority.search.marc')
                        ->run( term => $term, tag => '4%', subfield => 'a' );
        for my $m ( @marc ) {
                my $doc = $parser->parse_string($m);
                my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*');
                my $list = [ map { $_->textContent } @nodes ];
-               $client->respond( $list ) if (_empty_check($$list[0], 'metabib::subject_field_entry'));
+               $client->respond( $list ) if (_empty_check($$list[0], "metabib::${class}_field_entry"));
        }
        return undef;
 }
-__PACKAGE__->register_method(
-       api_name        => "open-ils.storage.authority.see_from.controlled",
-       method          => 'find_see_from_controlled',
-       api_level       => 1,
-       stream          => 1,
-       cachable        => 1,
-);
+for my $class ( qw/title author subject keyword series/ ) {
+       __PACKAGE__->register_method(
+               api_name        => "open-ils.storage.authority.$class.see_from.controlled",
+               method          => 'find_see_from_controlled',
+               api_level       => 1,
+               stream          => 1,
+               cachable        => 1,
+       );
+}
 
 sub find_see_also_from_controlled {
        my $self = shift;
        my $client = shift;
        my $term = shift;
 
+       (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o;
+
        my @marc = $self->method_lookup('open-ils.storage.authority.search.marc')
                        ->run( term => $term, tag => '5%', subfield => 'a' );
        for my $m ( @marc ) {
                my $doc = $parser->parse_string($m);
                my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*');
                my $list = [ map { $_->textContent } @nodes ];
-               $client->respond( $list ) if (_empty_check($$list[0], 'metabib::subject_field_entry'));
+               $client->respond( $list ) if (_empty_check($$list[0], "metabib::${class}_field_entry"));
        }
        return undef;
 }
-__PACKAGE__->register_method(
-       api_name        => "open-ils.storage.authority.see_also_from.controlled",
-       method          => 'find_see_also_from_controlled',
-       api_level       => 1,
-       stream          => 1,
-       cachable        => 1,
-);
+for my $class ( qw/title author subject keyword series/ ) {
+       __PACKAGE__->register_method(
+               api_name        => "open-ils.storage.authority.$class.see_also_from.controlled",
+               method          => 'find_see_also_from_controlled',
+               api_level       => 1,
+               stream          => 1,
+               cachable        => 1,
+       );
+}
 
 
 1;