1 package OpenILS::Application::Search::Authority;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenILS::Utils::Fieldmapper;
6 use OpenILS::Application::AppUtils;
10 use Time::HiRes qw(time);
11 use OpenSRF::EX qw(:try);
12 use Digest::MD5 qw(md5_hex);
14 sub crossref_authority {
20 my $session = OpenSRF::AppSession->create("open-ils.storage");
22 my $freq = $session->request(
23 "open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10);
24 my $areq = $session->request(
25 "open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10);
27 my $fr = $freq->gather(1);
28 my $al = $areq->gather(1);
30 return _auth_flatten( $term, $fr, $al, 1 );
43 last unless ($$x[$i]);
44 if ($string =~ /\W$/o) {
45 $string .= ' '.$$x[$i];
47 $string .= ' -- '.$$x[$i];
50 next if (lc($string) eq lc($term));
52 $hash{$string}++ if (lc($$x[0]) eq lc($term));
54 my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
56 # $from = [ @$from[0..4] ] if $limit;
62 last unless ($$x[$i]);
63 if ($string =~ /\W$/o) {
64 $string .= ' '.$$x[$i];
66 $string .= ' -- '.$$x[$i];
69 next if (lc($string) eq lc($term));
71 $hash{$string}++ if (lc($$x[0]) eq lc($term));
73 my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
75 # $also = [ @$also[0..4] ] if $limit;
78 return { from => $from, also => $also };
81 __PACKAGE__->register_method(
82 method => "crossref_authority",
83 api_name => "open-ils.search.authority.crossref",
85 note => "Searches authority data for existing controlled terms and crossrefs",
88 __PACKAGE__->register_method(
89 method => "crossref_authority_batch",
90 api_name => "open-ils.search.authority.crossref.batch",
93 Takes an array of class,term pair sub-arrays and performs an authority lookup for each
95 PARAMS( [ ["subject", "earth"], ["author","shakespeare"] ] );
97 Returns an object like so:
100 "term" : { "from" : [ ...], "also" : [...] }
101 "term2" : { "from" : [ ...], "also" : [...] }
106 sub crossref_authority_batch {
107 my( $self, $client, $reqs ) = @_;
111 my $session = OpenSRF::AppSession->create("open-ils.storage");
113 for my $req (@$reqs) {
115 my $class = $req->[0];
116 my $term = $req->[1];
117 next unless $class and $term;
118 warn "Sending authority request for $class : $term\n";
119 my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10);
120 my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10);
122 if( $lastr->[0] ) { #process old data while waiting on new data
123 my $cls = $lastr->[0];
124 my $trm = $lastr->[1];
125 my $fr = $lastr->[2];
126 my $al = $lastr->[3];
127 warn "Flattening $class : $term\n";
128 $response->{$cls} = {} unless exists $response->{$cls};
129 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1 );
132 $lastr->[0] = $class;
134 $lastr->[2] = $freq->gather(1);
135 $lastr->[3] = $areq->gather(1);
138 if( $lastr->[0] ) { #process old data while waiting on new data
139 my $cls = $lastr->[0];
140 my $trm = $lastr->[1];
141 my $fr = $lastr->[2];
142 my $al = $lastr->[3];
143 warn "Flattening $cls : $trm\n";
144 $response->{$cls} = {} unless exists $response->{$cls};
145 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1);