END IF; -- insert_on_deploy
END $INSERT$;
+-- returns
+CREATE OR REPLACE FUNCTION
+ metabib.browse_authority_is_unauthorized (mbe_id BIGINT, field_class TEXT)
+ RETURNS TABLE (auth_tag CHARACTER(3), atag INTEGER, auth_record BIGINT) AS
+$$
+ SELECT
+ acsaf.tag AS auth_tag,
+ ash.atag AS atag,
+ ash.record AS auth_record
+ FROM metabib.browse_entry_simple_heading_map map
+ JOIN authority.simple_heading ash ON (ash.id = map.simple_heading)
+ JOIN authority.control_set_authority_field acsaf on (acsaf.id = ash.atag)
+ JOIN authority.heading_field ahf ON (ahf.id = acsaf.heading_field)
+ JOIN authority.control_set_auth_field_metabib_field_map_refs refs_map
+ ON (ash.atag = refs_map.authority_field)
+ JOIN config.metabib_field cmf ON (cmf.id = refs_map.metabib_field)
+ WHERE map.entry = $1
+ AND cmf.field_class = $2
+ AND ahf.heading_purpose = 'variant'
+ LIMIT 1
+$$ LANGUAGE SQL;
+
+
-- BACK-PORTING https://bugs.launchpad.net/evergreen/+bug/1811689
-- which is not yet merged to master, but needed for 3.2 upgrade.
CREATE OR REPLACE FUNCTION reporter.enable_materialized_simple_record_trigger () RETURNS VOID AS $$
}
if ($results) {
- $self->gather_display_headings($results);
+ my $field_class = $params[0];
+ $self->gather_display_headings($results, $field_class);
$self->ctx->{browse_results} = $self->infer_browse_paging($results);
}
# Loops through the results and determines if the browse entry is authoritative or not
# then passes that entry to the appropriate set_heading function.
sub gather_display_headings {
- my ($self, $results) = @_;
+ my ($self, $results, $field_class) = @_;
for my $browse_term (@$results) {
$browse_term->{ref_headings} = {};
- my $auth_id = $self->is_not_authoritative($browse_term->{browse_entry});
+ my $auth_id = $self->is_not_authoritative(
+ $browse_term->{browse_entry}, $field_class);
if($auth_id) {
$self->set_see_heading($browse_term, $auth_id);
} else {
# and checks to see if that entry is a 400, 430 or 450 reference in another authority
# record. This is useful to know so we can filter out See Also references
# for non-authoritative entries.
+my %cmf_cache;
sub is_not_authoritative {
my $self = shift;
my $id = shift;
-
- my $result = $self->editor->json_query({
- select => {
- acsaf => ["tag"],
- ash => ["record"]
- },
- from => {
- acsaf => {
- ash => {
- fkey => "id", field => "atag",
- join => {
- mbeshm => {
- fkey => "id", field => "simple_heading",
- join => {
- mbe => {
- fkey => "entry", field => "id"
- }
- }
- }
- }
- }
- }
- },
- where => {"+mbe" => {id => $id}}
- });
+ my $field_class = shift;
- # If the result tag begins with a 4 we have an unauthorized heading so return true.
- if ($result->[0] && $result->[0]{tag} =~ /^4/) {
- return $result->[0]{record};
- }
+ my $result = $self->editor->json_query({
+ from => ['metabib.browse_authority_is_unauthorized', $id, $field_class]
+ })->[0];
+ return $result->{record} if $result;
+
return 0;
}