1 package OpenILS::Application::Search::Authority;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Application::AppUtils;
12 use Time::HiRes qw(time);
13 use OpenSRF::EX qw(:try);
14 use Digest::MD5 qw(md5_hex);
16 sub crossref_authority {
22 my $session = OpenSRF::AppSession->create("open-ils.storage");
25 my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term);
26 my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term);
28 my $fr = $freq->gather(1);
29 my $al = $areq->gather(1);
32 return _auth_flatten( $term, $fr, $al, 1 );
45 last unless ($$x[$i]);
46 if ($string =~ /\W$/o) {
47 $string .= ' '.$$x[$i];
49 $string .= ' -- '.$$x[$i];
52 next if (lc($string) eq lc($term));
54 $hash{$string}++ if (lc($$x[0]) eq lc($term));
56 my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
58 # $from = [ @$from[0..4] ] if $limit;
64 last unless ($$x[$i]);
65 if ($string =~ /\W$/o) {
66 $string .= ' '.$$x[$i];
68 $string .= ' -- '.$$x[$i];
71 next if (lc($string) eq lc($term));
73 $hash{$string}++ if (lc($$x[0]) eq lc($term));
75 my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
77 # $also = [ @$also[0..4] ] if $limit;
80 return { from => $from, also => $also };
83 __PACKAGE__->register_method(
84 method => "crossref_authority",
85 api_name => "open-ils.search.authority.crossref",
87 note => "Searches authority data for existing controlled terms and crossrefs",
90 __PACKAGE__->register_method(
91 method => "crossref_authority_batch",
92 api_name => "open-ils.search.authority.crossref.batch",
95 Takes an array of class,term pair sub-arrays and performs an authority lookup for each
97 PARAMS( [ ["subject", "earth"], ["author","shakespeare"] ] );
99 Returns an object like so:
102 "term" : { "from" : [ ...], "also" : [...] }
103 "term2" : { "from" : [ ...], "also" : [...] }
108 sub crossref_authority_batch {
109 my( $self, $client, $reqs ) = @_;
113 my $session = OpenSRF::AppSession->create("open-ils.storage");
115 for my $req (@$reqs) {
117 my $class = $req->[0];
118 my $term = $req->[1];
119 next unless $class and $term;
120 warn "Sending authority request for $class : $term\n";
121 my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term);
122 my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term);
124 if( $lastr->[0] ) { #process old data while waiting on new data
125 my $cls = $lastr->[0];
126 my $trm = $lastr->[1];
127 my $fr = $lastr->[2];
128 my $al = $lastr->[3];
129 warn "Flattening $class : $term\n";
130 $response->{$cls} = {} unless exists $response->{$cls};
131 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1 );
134 $lastr->[0] = $class;
136 $lastr->[2] = $freq->gather(1);
137 $lastr->[3] = $areq->gather(1);
140 if( $lastr->[0] ) { #process old data while waiting on new data
141 my $cls = $lastr->[0];
142 my $trm = $lastr->[1];
143 my $fr = $lastr->[2];
144 my $al = $lastr->[3];
145 warn "Flattening $cls : $trm\n";
146 $response->{$cls} = {} unless exists $response->{$cls};
147 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1);