added support for all authority xrefs -- XXX we need MADS to do facets :(
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Nov 2005 20:57:20 +0000 (20:57 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Nov 2005 20:57:20 +0000 (20:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1999 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm

index 94a6899..d0ef219 100644 (file)
@@ -13,29 +13,64 @@ use Time::HiRes qw(time);
 use OpenSRF::EX qw(:try);
 use Digest::MD5 qw(md5_hex);
 
-sub crossref_subject {
+sub crossref_authority {
        my $self = shift;
        my $client = shift;
-       my $subject = shift;
+       my $class = shift;
+       my $term = shift;
 
        my $session = OpenSRF::AppSession->create("open-ils.storage");
        $session->connect;
 
-       my $freq = $session->request('open-ils.storage.authority.subject.see_from.controlled.atomic',$subject);
-       my $areq = $session->request('open-ils.storage.authority.subject.see_also_from.controlled.atomic',$subject);
+       my $freq = $session->request("open-ils.storage.authority.$class.see_from.controlled.atomic",$term);
+       my $areq = $session->request("open-ils.storage.authority.$class.see_also_from.controlled.atomic",$term);
 
-       my $from = $freq->gather(1);
-       my $also = $areq->gather(1);
+       my $fr = $freq->gather(1);
+       my $al = $areq->gather(1);
+
+       my %hash = ();
+       for my $x (@$fr) {
+               my $string = $$x[0];
+               for my $i (1..10) {
+                       last unless ($$x[$i]);
+                       if ($string =~ /\W$/o) {
+                               $string .= ' '.$$x[$i];
+                       } else {
+                               $string .= ' -- '.$$x[$i];
+                       }
+               }
+               next if (lc($string) eq lc($term));
+               $hash{$string}++;
+       }
+       my $from = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
+
+       %hash = ();
+       for my $x (@$al) {
+               my $string = $$x[0];
+               for my $i (1..10) {
+                       last unless ($$x[$i]);
+                       if ($string =~ /\W$/o) {
+                               $string .= ' '.$$x[$i];
+                       } else {
+                               $string .= ' -- '.$$x[$i];
+                       }
+               }
+               next if (lc($string) eq lc($term));
+               $hash{$string}++;
+       }
+       my $also = [ sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash ];
 
        $session->disconnect;
 
+       
+
        return { from => $from, also => $also };
 }
 __PACKAGE__->register_method(
-        method         => "crossref_subject",
-        api_name       => "open-ils.search.authority.subject.crossref",
-        argc           => 1
-        note           => "Searches authority data for existing subject controlled terms and crossrefs",
+        method         => "crossref_authority",
+        api_name       => "open-ils.search.authority.crossref",
+        argc           => 2
+        note           => "Searches authority data for existing controlled terms and crossrefs",
 );