]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm
adjusting rank and "title" searching
[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                 $hash{$string}++ if (lc($$x[0]) eq lc($term));
45         }
46         my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
47
48         %hash = ();
49         for my $x (@$al) {
50                 my $string = $$x[0];
51                 for my $i (1..10) {
52                         last unless ($$x[$i]);
53                         if ($string =~ /\W$/o) {
54                                 $string .= ' '.$$x[$i];
55                         } else {
56                                 $string .= ' -- '.$$x[$i];
57                         }
58                 }
59                 next if (lc($string) eq lc($term));
60                 $hash{$string}++;
61                 $hash{$string}++ if (lc($$x[0]) eq lc($term));
62         }
63         my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
64
65         $session->disconnect;
66
67         
68
69         return { from => $from, also => $also };
70 }
71 __PACKAGE__->register_method(
72         method          => "crossref_authority",
73         api_name        => "open-ils.search.authority.crossref",
74         argc            => 2, 
75         note            => "Searches authority data for existing controlled terms and crossrefs",
76 );              
77
78
79 1;