From: Lebbeous Fogle-Weekley Date: Fri, 3 May 2013 19:49:56 +0000 (-0400) Subject: linked authority records working; leading article warning working X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=14e45c81b7b90c13650c8a5b57da2f7a61788e9c;p=evergreen%2Fequinox.git linked authority records working; leading article warning working Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm index 423903c969..33db369c96 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -82,6 +82,7 @@ sub flesh_browse_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) { # Get all linked authority records themselves my $linked_authorities = $self->editor->json_query({ @@ -94,22 +95,23 @@ sub flesh_browse_results { where => {"+aalink" => {target => \@auth_ids}} }) or return; + my %linked_headings_by_auth_id; + # 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 = + my $acsaf_table = $self->ctx->{get_authority_fields}->($row->{control_set}); $row->{headings} = []; - # BEGIN isolate in eval? + # XXX BEGIN isolate in eval? in case of bad marc causing a die()? my $record = new_from_xml MARC::Record($row->{marc}); - foreach my $acsaf (@$acsaf_list) { + foreach my $acsaf (values(%$acsaf_table)) { my @fields = $record->field($acsaf->tag); my @headings; + foreach (@fields) { my $heading = ""; foreach my $sf (split "", $acsaf->sf_list) { @@ -118,15 +120,28 @@ sub flesh_browse_results { push @headings, $heading; } - push @{$row->{headings}}, {$acsaf->id => \@headings}; + # Remember: main_entry is a link field, so for it to evaluate + # to true means that we *have* (and therefore *aren't*) a main + # entry. The rest of the time when main_entry is undef we + # *are* a main entry. + # + # For this, we only want non-main entries. + push @{$row->{headings}}, {$acsaf->id => \@headings} + if @headings and $acsaf->main_entry; } - # END isolate in eval? + # XXX END isolate in eval? - $linked_headings_by_target{$row->{target}} = $row; + $linked_headings_by_auth_id{$row->{id}} = $row; } # XXX TODO count bibs linked to each linked auth record? - print FH Dumper(\%linked_headings_by_target), "\n"; +# print FH Dumper(\%linked_headings_by_auth_id), "\n"; + + foreach my $row (@$results) { + $row->{authorities} = [ + map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}} + ]; + } } close FH; @@ -187,6 +202,35 @@ sub deduce_possible_paging { } } +sub leading_article_test { + my ($self, $qtype, $bterm) = @_; + + my $flag_name = "opac.browse.warnable_regexp_per_class"; + my $flag = $self->ctx->{get_cgf}->($flag_name); + + return unless $flag->enabled; + + my $map; + + eval { $map = OpenSRF::Utils::JSON->JSON2perl($flag->value); }; + if ($@) { + $logger->warn("cgf '$flag_name' enabled but value is invalid JSON? $@"); + return; + } + + # Don't crash over any of the things that could go wrong in here: + eval { + if ($map->{$qtype}) { + if ($bterm =~ qr/$map->{$qtype}/i) { + $self->ctx->{browse_leading_article_warning} = 1; + } + } + }; + if ($@) { + $logger->warn("cgf '$flag_name' has valid JSON in value, but: $@"); + } +} + sub load_browse { my ($self) = @_; @@ -196,8 +240,13 @@ sub load_browse { $self->ctx->{more_back} = 0; if ($self->cgi->param('qtype') and $self->cgi->param('bterm')) { - my ($cache_key, $limit, $offset, @params) = - $self->prepare_browse_parameters; + + $self->leading_article_test( + $self->cgi->param('qtype'), + $self->cgi->param('bterm') + ); + + my ($cache_key, $limit, $offset, @params) = $self->prepare_browse_parameters; my $results = $browse_cache->get_cache($cache_key) || $self->load_browse_impl($limit, $offset, @params); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index f2abacd3c8..8e7a1ec434 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -232,9 +232,13 @@ sub init_ro_object_cache { $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}; + if (not exists $cache{authority_fields}{$ctx->{locale}}{$control_set}) { + my $acs = $e->search_authority_control_set_authority_field( + {control_set => $control_set} + ) or return; + $cache{authority_fields}{$ctx->{locale}}{$control_set} = + +{ map { $_->id => $_ } @$acs }; + } return $cache{authority_fields}{$ctx->{locale}}{$control_set}; }; diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 404480f018..e419dae15c 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1537,7 +1537,7 @@ BEGIN FROM authority.control_set_authority_field WHERE tag IN ( SELECT UNNEST( - XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[] + XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml)::TEXT[] ) ) LIMIT 1; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql index 0424a77272..790187692d 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.config-metabib-interauthority.sql @@ -33,7 +33,7 @@ BEGIN FROM authority.control_set_authority_field WHERE tag IN ( SELECT UNNEST( - XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc::XML)::TEXT[] + XPATH('//*[starts-with(@tag,"1")]/@tag',rec_marc_xml::XML)::TEXT[] ) ) LIMIT 1; diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql index a93d6ba905..460983e4c2 100644 --- a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql @@ -2,9 +2,7 @@ BEGIN; -- check whether patch can be applied -- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version); - -ALTER TABLE metabib.browse_entry_def_map - ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id) +ALTER TABLE metabib.browse_entry_def_map ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id) ON DELETE SET NULL; ALTER TABLE config.metabib_field ADD COLUMN authority_xpath TEXT; @@ -6885,6 +6883,19 @@ Revision 1.2 - Added Log Comment 2003/03/24 19:37:42 ckeith -- ---------------------------------------------------- -- XXX TODO From here down, add this to stock SQL files +INSERT INTO config.global_flag (name, value, enabled, label) +VALUES ( + 'opac.browse.warnable_regexp_per_class', + '{"title": "^(a|the|an)\\s"}', + FALSE, + oils_i18n_gettext( + 'opac.browse.warnable_regexp_per_class', + 'Map of search classes to regular expressions to warn user about leading articles.', + 'cgf', + 'label' + ) +); + ALTER TABLE metabib.browse_entry ADD COLUMN sort_value TEXT; CREATE OR REPLACE FUNCTION metabib.browse_entry_sort_value() diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2 index 3c4b6b4a78..c6ae787138 100644 --- a/Open-ILS/src/templates/opac/browse.tt2 +++ b/Open-ILS/src/templates/opac/browse.tt2 @@ -9,14 +9,16 @@ ctx.page_title = l("Browse the Catalog"); blimit = CGI.param('blimit') || 10; boffset = CGI.param('boffset') || 0; - %] + + depart_list = ['blimit', 'bterm', 'boffset']; +%]
[%# XXX TODO Give searchbar.tt2 more smarts so we can just do: # INCLUDE "opac/parts/searchbar.tt2" %]
- [% l('Search the Catalog') %] - [% l('Search the Catalog') %] + [%l('Advanced Search')%] [% l('Browse the Catalog') %]
@@ -79,6 +81,11 @@ "to library staff.") %] [% ELSE %] + [% IF ctx.browse_leading_article_warning %] +
+ [% l("Your browse term seems to begin with an article. You might better results by omitting the article.") %] +
+ [% END %]
    [% FOR result IN ctx.browse_results %]
  • @@ -89,6 +96,22 @@ }) %]">[% result.value | html %] ([% result.sources %]) + [% IF result.authorities %] +
      + [% FOR a IN result.authorities; + NEXT UNLESS a.control_set; # XXX can't deal + + # get_authority_fields is fast and cache-y. + acs = ctx.get_authority_fields(a.control_set); + FOR h IN a.headings; + field_id = h.keys.0; + field = acs.$field_id; + headings_themselves = h.values.0 %] +
    • [% field.name %] [% headings_themselves.join(";") %]
    • + [% END %] + [% END %] +
    + [% END %]
  • [% END %]
diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2 index b3e497b039..ba4eec73d5 100644 --- a/Open-ILS/src/templates/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates/opac/css/style.css.tt2 @@ -1531,3 +1531,7 @@ a.preflib_change { .browse-shortcuts { font-size: 120%; } +.browse-leading-article-warning { + font-style: italic; + font-size: 110%; +}