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(
26 "open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10);
27 my $areq = $session->request(
28 "open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10);
30 my $fr = $freq->gather(1);
31 my $al = $areq->gather(1);
34 return _auth_flatten( $term, $fr, $al, 1 );
47 last unless ($$x[$i]);
48 if ($string =~ /\W$/o) {
49 $string .= ' '.$$x[$i];
51 $string .= ' -- '.$$x[$i];
54 next if (lc($string) eq lc($term));
56 $hash{$string}++ if (lc($$x[0]) eq lc($term));
58 my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
60 # $from = [ @$from[0..4] ] if $limit;
66 last unless ($$x[$i]);
67 if ($string =~ /\W$/o) {
68 $string .= ' '.$$x[$i];
70 $string .= ' -- '.$$x[$i];
73 next if (lc($string) eq lc($term));
75 $hash{$string}++ if (lc($$x[0]) eq lc($term));
77 my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
79 # $also = [ @$also[0..4] ] if $limit;
82 return { from => $from, also => $also };
85 __PACKAGE__->register_method(
86 method => "crossref_authority",
87 api_name => "open-ils.search.authority.crossref",
89 note => "Searches authority data for existing controlled terms and crossrefs",
92 __PACKAGE__->register_method(
93 method => "crossref_authority_batch",
94 api_name => "open-ils.search.authority.crossref.batch",
97 Takes an array of class,term pair sub-arrays and performs an authority lookup for each
99 PARAMS( [ ["subject", "earth"], ["author","shakespeare"] ] );
101 Returns an object like so:
104 "term" : { "from" : [ ...], "also" : [...] }
105 "term2" : { "from" : [ ...], "also" : [...] }
110 sub crossref_authority_batch {
111 my( $self, $client, $reqs ) = @_;
115 my $session = OpenSRF::AppSession->create("open-ils.storage");
117 for my $req (@$reqs) {
119 my $class = $req->[0];
120 my $term = $req->[1];
121 next unless $class and $term;
122 warn "Sending authority request for $class : $term\n";
123 my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term, 10);
124 my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term, 10);
126 if( $lastr->[0] ) { #process old data while waiting on new data
127 my $cls = $lastr->[0];
128 my $trm = $lastr->[1];
129 my $fr = $lastr->[2];
130 my $al = $lastr->[3];
131 warn "Flattening $class : $term\n";
132 $response->{$cls} = {} unless exists $response->{$cls};
133 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1 );
136 $lastr->[0] = $class;
138 $lastr->[2] = $freq->gather(1);
139 $lastr->[3] = $areq->gather(1);
142 if( $lastr->[0] ) { #process old data while waiting on new data
143 my $cls = $lastr->[0];
144 my $trm = $lastr->[1];
145 my $fr = $lastr->[2];
146 my $al = $lastr->[3];
147 warn "Flattening $cls : $trm\n";
148 $response->{$cls} = {} unless exists $response->{$cls};
149 $response->{$cls}->{$trm} = _auth_flatten( $trm, $fr, $al, 1);