initial code not yet work for authorities 'see also' type stuff
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 2 May 2013 22:44:25 +0000 (18:44 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 3 May 2013 13:57:50 +0000 (09:57 -0400)
has_browse_entry() refined as well

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/browse.tt2
Open-ILS/src/templates/opac/parts/searchbar.tt2

index ccc7117..a76a174 100644 (file)
@@ -5679,6 +5679,19 @@ SELECT  usr,
                        <link field="record" reltype="has_a" key="id" map="" class="are"/>
                </links>
        </class>
+       <class id="aalink" controller="open-ils.cstore" oils_obj:fieldmapper="authority::authority_linking" oils_persist:tablename="authority.authority_linking" reporter:label="Authority to Authority Linking">
+               <fields oils_persist:primary="id" oils_persist:sequence="authority.authority_linking_id_seq">
+                       <field name="id" reporter:label="ID" reporter:datatype="id" />
+                       <field name="source" reporter:label="Source Record" reporter:datatype="link" />
+                       <field name="target" reporter:label="Target Record" reporter:datatype="link" />
+                       <field name="field" reporter:label="Authority Field" reporter:datatype="link" />
+               </fields>
+               <links>
+                       <link field="source" reltype="has_a" key="id" map="" class="are"/>
+                       <link field="target" reltype="has_a" key="id" map="" class="are"/>
+                       <link field="field" reltype="has_a" key="id" map="" class="acsaf"/>
+               </links>
+       </class>
        <class id="cnct" controller="open-ils.cstore" oils_obj:fieldmapper="config::non_cataloged_type" oils_persist:tablename="config.non_cataloged_type" reporter:label="Non-cataloged Type">
                <fields oils_persist:primary="id" oils_persist:sequence="config.non_cataloged_type_id_seq">
                        <field reporter:label="Circulation Duration" name="circ_duration" reporter:datatype="interval"/>
index 97d140f..27f0ff5 100644 (file)
@@ -1112,8 +1112,10 @@ sub flatten {
                 }
 
             } elsif ($filter->name eq 'has_browse_entry') {
-                if (@{$filter->args} > 0) {
-                    $from .= "\n" . $spc x 3 . sprintf("INNER JOIN metabib.browse_entry_def_map mbedm ON (mbedm.source = m.source AND mbedm.entry = %d)", $filter->args->[0]);
+                if (@{$filter->args} >= 2) {
+                    my $entry = int(shift @{$filter->args});
+                    my $fields = join(",", map(int, @{$filter->args}));
+                    $from .= "\n" . $spc x 3 . sprintf("INNER JOIN metabib.browse_entry_def_map mbedm ON (mbedm.source = m.source AND mbedm.entry = %d AND mbedm.def IN (%s))", $entry, $fields);
                 }
             } elsif ($filter->name eq 'edit_date' or $filter->name eq 'create_date') {
                 # bre.create_date and bre.edit_date filtering
index af129b1..423903c 100644 (file)
@@ -13,6 +13,7 @@ use OpenSRF::Utils::SettingsClient;
 
 use Digest::MD5 qw/md5_hex/;
 use Apache2::Const -compile => qw/OK/;
+use MARC::Record;
 use Data::Dumper;
 $Data::Dumper::Indent = 0;
 
@@ -64,23 +65,70 @@ sub prepare_browse_parameters {
     );
 }
 
-# This changes $results and returns 1 for success, undef for failure.
-# $results must be an arrayref of result rows from the DB's metabib.browse().
+# flesh_browse_results() attaches data from authority records. It
+# changes $results and returns 1 for success, undef for failure (in which
+# case $self->editor->event should always point to the reason for failure).
+# $results must be an arrayref of result rows from the DB's metabib.browse()
 sub flesh_browse_results {
     my ($self, $results) = @_;
 
-    my @auth_ids = map { split /,/, $_->{authorities} } @$results;
+    # Turn all comma-seprated strings of numbers into array.
+    $_->{authorities} = [split /,/, $_->{authorities}] foreach @$results;
 
+    # Group them in one arrray, not worrying about dupes because IN () takes
+    # care of that.
+    my @auth_ids = map { @{$_->{authorities}} } @$results;
+
+    open FH, ">/tmp/lfw-auth-" . time() or die "LFW XXX $!";
+    print FH Dumper(\@auth_ids), "\n";
+    print FH Dumper($results), "\n";
     if (@auth_ids) {
-        # select ash.*
-        # from authority.record_entry are
-        # join authority.control_set acs on (are.control_set = acs.id)
-        # join authority.control_set_authority_field
-        # XXX wait what am I doing here?
-        my $authorities = $self->editor->json_query({
-            ""
+        # Get all linked authority records themselves
+        my $linked_authorities = $self->editor->json_query({
+            select => {are => [qw/id marc control_set/], aalink => ["target"]},
+            from => {
+                aalink => {
+                    are => { field => "id", fkey => "source" }
+                }
+            },
+            where => {"+aalink" => {target => \@auth_ids}}
         }) or return;
+
+        # Then use the linked authority records' control sets to find and
+        # pick out non-main-entry headings.  Build the headings and make a
+        # combined data structure for the template's use.
+
+        my %linked_headings_by_target;
+
+        foreach my $row (@$linked_authorities) {
+            my $acsaf_list =
+                $self->ctx->{get_authority_fields}->($row->{control_set});
+
+            $row->{headings} = [];
+            # BEGIN isolate in eval?
+            my $record = new_from_xml MARC::Record($row->{marc});
+            foreach my $acsaf (@$acsaf_list) {
+                my @fields = $record->field($acsaf->tag);
+                my @headings;
+                foreach (@fields) {
+                    my $heading = "";
+                    foreach my $sf (split "", $acsaf->sf_list) {
+                        $heading .= $_->subfield($sf) || "";
+                    }
+                    push @headings, $heading;
+                }
+
+                push @{$row->{headings}}, {$acsaf->id => \@headings};
+            }
+            # END isolate in eval?
+
+            $linked_headings_by_target{$row->{target}} = $row;
+        }
+
+        # XXX TODO count bibs linked to each linked auth record?
+        print FH Dumper(\%linked_headings_by_target), "\n";
     }
+    close FH;
 
     return 1;
 }
@@ -103,14 +151,14 @@ sub load_browse_impl {
         $self->ctx->{browse_error} = 1;
 
         return;
-    }#elsif (not $self->flesh_browse_results($results)) {
-#        $logger->warn(
-#            "error in browse (flesh): " . $self->editor->event->{textcode}
-#        );
-#        $self->ctx->{browse_error} = 1;
-#
-#        return;
-#    }
+    } elsif (not $self->flesh_browse_results($results)) {
+        $logger->warn(
+            "error in browse (flesh): " . $self->editor->event->{textcode}
+        );
+        $self->ctx->{browse_error} = 1;
+
+        return;
+    }
 
     return $results;
 }
index 93cc3e1..f2abacd 100644 (file)
@@ -18,7 +18,8 @@ our %cache = ( # cached data
     search_filter_groups => {en_us => {}},
     aou_tree => {en_us => undef},
     aouct_tree => {},
-    eg_cache_hash => undef
+    eg_cache_hash => undef,
+    authority_fields => {en_us => {}}
 );
 
 sub init_ro_object_cache {
@@ -227,6 +228,17 @@ sub init_ro_object_cache {
         return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
     };
 
+    # retrieve and cache acsaf values
+    $ro_object_subs->{get_authority_fields} = sub {
+        my ($control_set) = @_;
+
+        $cache{authority_fields}{$ctx->{locale}}{$control_set} =
+            $e->search_authority_control_set_authority_field({control_set => $control_set})
+                unless exists $cache{authority_fields}{$ctx->{locale}}{$control_set};
+
+        return $cache{authority_fields}{$ctx->{locale}}{$control_set};
+    };
+
     $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;
 }
 
index 9edf2bc..3c4b6b4 100644 (file)
                     [% FOR result IN ctx.browse_results %]
                         <li class="browse-result">
                             <span class="browse-result-value">
-                                <a href="[% mkurl(ctx.opac_root _ '/results', {'fi:has_browse_entry' => result.browse_entry}) %]">[% result.value | html %]</a>
+                                <a href="[% mkurl(
+                                    ctx.opac_root _ '/results', {
+                                        'fi:has_browse_entry' => (result.browse_entry _ ',' _ result.fields)
+                                    }) %]">[% result.value | html %]</a>
                             </span>
                             <span class="browse-result-sources">([% result.sources %])</span>
                         </li>
index 2034a97..52381a8 100644 (file)
@@ -7,7 +7,7 @@
         <span class="search_catalog_lbl">[% l('Search the Catalog') %]</span>
         <a href="[% mkurl(ctx.opac_root _ '/advanced') %]"
             id="home_adv_search_link">[% l('Advanced Search') %]</a>
-        <span class="browse_the_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/browse') %]">[% l('Browse the Catalog') %]</a></span>
+        <span class="browse_the_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/browse', {}, ['fi:has_browse_entry']) %]">[% l('Browse the Catalog') %]</a></span>
     </div>
     <div class="searchbar">[%- l('Search ');
         IF search.basic_config.type == 'attr';