]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm
d0ef2197141285a1f24708c244b5e4fb66127845
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Authority.pm
1 package OpenILS::Application::Search::Authority;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
5 use OpenILS::EX;
6
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Application::AppUtils;
9
10 use JSON;
11
12 use Time::HiRes qw(time);
13 use OpenSRF::EX qw(:try);
14 use Digest::MD5 qw(md5_hex);
15
16 sub crossref_authority {
17         my $self = shift;
18         my $client = shift;
19         my $class = shift;
20         my $term = shift;
21
22         my $session = OpenSRF::AppSession->create("open-ils.storage");
23         $session->connect;
24
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);
27
28         my $fr = $freq->gather(1);
29         my $al = $areq->gather(1);
30
31         my %hash = ();
32         for my $x (@$fr) {
33                 my $string = $$x[0];
34                 for my $i (1..10) {
35                         last unless ($$x[$i]);
36                         if ($string =~ /\W$/o) {
37                                 $string .= ' '.$$x[$i];
38                         } else {
39                                 $string .= ' -- '.$$x[$i];
40                         }
41                 }
42                 next if (lc($string) eq lc($term));
43                 $hash{$string}++;
44         }
45         my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
46
47         %hash = ();
48         for my $x (@$al) {
49                 my $string = $$x[0];
50                 for my $i (1..10) {
51                         last unless ($$x[$i]);
52                         if ($string =~ /\W$/o) {
53                                 $string .= ' '.$$x[$i];
54                         } else {
55                                 $string .= ' -- '.$$x[$i];
56                         }
57                 }
58                 next if (lc($string) eq lc($term));
59                 $hash{$string}++;
60         }
61         my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
62
63         $session->disconnect;
64
65         
66
67         return { from => $from, also => $also };
68 }
69 __PACKAGE__->register_method(
70         method          => "crossref_authority",
71         api_name        => "open-ils.search.authority.crossref",
72         argc            => 2, 
73         note            => "Searches authority data for existing controlled terms and crossrefs",
74 );              
75
76
77 1;