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({
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) {
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;
}
}
+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) = @_;
$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);
-- 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;
-- ----------------------------------------------------
-- 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()
ctx.page_title = l("Browse the Catalog");
blimit = CGI.param('blimit') || 10;
boffset = CGI.param('boffset') || 0;
- %]
+
+ depart_list = ['blimit', 'bterm', 'boffset'];
+%]
<div id="search-wrapper">
[%# XXX TODO Give searchbar.tt2 more smarts so we can just do:
# INCLUDE "opac/parts/searchbar.tt2" %]
<div id="search-tools">
- <span class="search_catalog_lbl">[% l('Search the Catalog') %]</span>
- <span><a href="[% mkurl(ctx.opac_root _ '/advanced') %]"
+ <span class="search_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/home', {}, depart_list) %]">[% l('Search the Catalog') %]</a></span>
+ <span><a href="[% mkurl(ctx.opac_root _ '/advanced', {}, depart_list) %]"
id="home_adv_search_link">[%l('Advanced Search')%]</a></span>
<span>[% l('Browse the Catalog') %]</span>
</div>
"to library staff.") %]
</span>
[% ELSE %]
+ [% IF ctx.browse_leading_article_warning %]
+ <div class="browse-leading-article-warning">
+ [% l("Your browse term seems to begin with an article. You might better results by omitting the article.") %]
+ </div>
+ [% END %]
<ul class="browse-result-list">
[% FOR result IN ctx.browse_results %]
<li class="browse-result">
}) %]">[% result.value | html %]</a>
</span>
<span class="browse-result-sources">([% result.sources %])</span>
+ [% IF result.authorities %]
+ <ul class="browse-result-authority-headings">
+ [% 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 %]
+ <li>[% field.name %] <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ a.target _ ']'}) %]">[% headings_themselves.join(";") %]</a></li>
+ [% END %]
+ [% END %]
+ </ul>
+ [% END %]
</li>
[% END %]
</ul>