From: Mike Rylander Date: Tue, 3 May 2011 22:04:22 +0000 (-0400) Subject: Munged trunk merge X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=50d9ca5e44f6b149901d0caaacc168c94c7deb10;p=evergreen%2Fequinox.git Munged trunk merge --- 50d9ca5e44f6b149901d0caaacc168c94c7deb10 diff --cc Open-ILS/src/sql/Pg/011.schema.authority.sql index d54800ac1f,133a2438f7..49e0879e97 --- a/Open-ILS/src/sql/Pg/011.schema.authority.sql +++ b/Open-ILS/src/sql/Pg/011.schema.authority.sql @@@ -123,84 -92,108 +123,88 @@@ CREATE INDEX authority_full_rec_index_v /* Enable LIKE to use an index for database clusters with locales other than C or POSIX */ CREATE INDEX authority_full_rec_value_tpo_index ON authority.full_rec (value text_pattern_ops); +-- Adding indexes using oils_xpath_string() for the main entry tags described in +-- authority.control_set_authority_field would speed this up, if we ever want to use it, though +-- the existing index on authority.normalize_heading() helps already with a record in hand CREATE OR REPLACE VIEW authority.tracing_links AS - SELECT main.record AS record, - main.id AS main_id, - main.tag AS main_tag, - main.value AS main_value, - substr(link.value,1,1) AS relationship, - substr(link.value,2,1) AS use_restriction, - substr(link.value,3,1) AS deprecation, - substr(link.value,4,1) AS display_restriction, - link_value.id AS link_id, - link_value.tag AS link_tag, - link_value.value AS link_value - FROM authority.full_rec main - JOIN authority.full_rec link - ON ( link.record = main.record - AND link.tag in ((main.tag::int + 400)::text, (main.tag::int + 300)::text) - AND link.subfield = 'w' ) - JOIN authority.full_rec link_value - ON ( link_value.record = main.record - AND link_value.tag = link.tag - AND link_value.subfield = 'a' ) - WHERE main.tag IN ('100','110','111','130','150','151','155','180','181','182','185') - AND main.subfield = 'a'; + SELECT main.record AS record, + main.id AS main_id, + main.tag AS main_tag, + oils_xpath_string('//*[@tag="'||main.tag||'"]/*[local-name()="subfield"]', are.marc) AS main_value, + authority.normalize_heading(are.marc) AS normalized_main_value, + substr(link.value,1,1) AS relationship, + substr(link.value,2,1) AS use_restriction, + substr(link.value,3,1) AS deprecation, + substr(link.value,4,1) AS display_restriction, + link.id AS link_id, + link.tag AS link_tag, + oils_xpath_string('//*[@tag="'||link.tag||'"]/*[local-name()="subfield"]', are.marc) AS link_value + FROM authority.full_rec main + JOIN authority.record_entry are ON (main.record = are.id) + JOIN authority.control_set_authority_field main_entry + ON (main_entry.tag = main.tag + AND main_entry.main_entry IS NULL + AND main.subfield = 'a' ) + JOIN authority.control_set_authority_field sub_entry + ON (main_entry.id = sub_entry.main_entry) + JOIN authority.full_rec link + ON (link.record = main.record + AND link.tag = sub_entry.tag + AND link.subfield = 'w' ); -- Function to generate an ephemeral overlay template from an authority record -CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( TEXT, BIGINT ) RETURNS TEXT AS $func$ - - use MARC::Record; - use MARC::File::XML (BinaryEncoding => 'UTF-8'); - use MARC::Charset; - - MARC::Charset->assume_unicode(1); - - my $xml = shift; - my $r = MARC::Record->new_from_xml( $xml ); - - return undef unless ($r); - - my $id = shift() || $r->subfield( '901' => 'c' ); - $id =~ s/^\s*(?:\([^)]+\))?\s*(.+)\s*?$/$1/; - return undef unless ($id); # We need an ID! - - my $tmpl = MARC::Record->new(); - $tmpl->encoding( 'UTF-8' ); - - my @rule_fields; - for my $field ( $r->field( '1..' ) ) { # Get main entry fields from the authority record - - my $tag = $field->tag; - my $i1 = $field->indicator(1); - my $i2 = $field->indicator(2); - my $sf = join '', map { $_->[0] } $field->subfields; - my @data = map { @$_ } $field->subfields; - - my @replace_them; - - # Map the authority field to bib fields it can control. - if ($tag >= 100 and $tag <= 111) { # names - @replace_them = map { $tag + $_ } (0, 300, 500, 600, 700); - } elsif ($tag eq '130') { # uniform title - @replace_them = qw/130 240 440 730 830/; - } elsif ($tag >= 150 and $tag <= 155) { # subjects - @replace_them = ($tag + 500); - } elsif ($tag >= 180 and $tag <= 185) { # floating subdivisions - @replace_them = qw/100 400 600 700 800 110 410 610 710 810 111 411 611 711 811 130 240 440 730 830 650 651 655/; - } else { - next; - } - - # Dummy up the bib-side data - $tmpl->append_fields( - map { - MARC::Field->new( $_, $i1, $i2, @data ) - } @replace_them - ); - - # Construct some 'replace' rules - push @rule_fields, map { $_ . $sf . '[0~\)' .$id . '$]' } @replace_them; - } - - # Insert the replace rules into the template - $tmpl->append_fields( - MARC::Field->new( '905' => ' ' => ' ' => 'r' => join(',', @rule_fields ) ) - ); - - $xml = $tmpl->as_xml_record; - $xml =~ s/^<\?.+?\?>$//mo; - $xml =~ s/\n//sgo; - $xml =~ s/>\s+ 0 THEN + FOR bib_field IN SELECT * FROM authority.control_set_bib_field WHERE authority_field = main_entry.id LOOP + replace_data := replace_data || XMLELEMENT( name datafield, bib_field.tag AS tag, XPATH('//*[local-name()="subfield"]',auth_field[1])::XML[]); + replace_rules := replace_rules || ( bib_field.tag || main_entry.sf_list || E'[0~\\)' || auth_id || '$]' ); + END LOOP; + EXIT; + END IF; + END LOOP; -$func$ LANGUAGE PLPERLU; + RETURN XMLELEMENT( + name record, + XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns) + XMLELEMENT( name leader, '00881nam a2200193 4500'), + replace_data, + XMLELEMENT( + name datafield, + '905' AS tag, + ' ' AS ind1, + ' ' AS ind2, + XMLELEMENT( + name subfield, + 'r' AS code, + ARRAY_TO_STRING(replace_rules,',') + ) + ) + )::TEXT; +END; +$f$ STABLE LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( BIGINT ) RETURNS TEXT AS $func$ - SELECT authority.generate_overlay_template( marc, id ) FROM authority.record_entry WHERE id = $1; -$func$ LANGUAGE SQL; - -CREATE OR REPLACE FUNCTION authority.generate_overlay_template ( TEXT ) RETURNS TEXT AS $func$ - SELECT authority.generate_overlay_template( $1, NULL ); ++ SELECT authority.generate_overlay_template( marc ) FROM authority.record_entry WHERE id = $1; + $func$ LANGUAGE SQL; + CREATE OR REPLACE FUNCTION authority.merge_records ( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$ DECLARE moved_objects INT := 0;