]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/1100.data.display-field-seed-data.sql
LP#1744385: Stamping upgrade scripts for search and display infrastructure improvements
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 1100.data.display-field-seed-data.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('1100', :eg_version);
4
5 -- NEW config.metabib_field entries
6
7 UPDATE config.metabib_field SET display_xpath = facet_xpath, display_field = TRUE WHERE id = 33;
8
9 INSERT INTO config.metabib_field (id, field_class, name, 
10     label, xpath, display_field, search_field, browse_field)
11 VALUES (
12     38, 'identifier', 'edition', 
13     oils_i18n_gettext(38, 'Edition', 'cmf', 'label'),
14     $$//mods33:mods/mods33:originInfo//mods33:edition[1]$$,
15     TRUE, TRUE, FALSE
16 );
17
18 INSERT INTO config.metabib_field (id, field_class, name, 
19     label, xpath, display_field, search_field, browse_field)
20 VALUES (
21     39, 'keyword', 'physical_description', 
22     oils_i18n_gettext(39, 'Physical Descrption', 'cmf', 'label'),
23     $$(//mods33:mods/mods33:physicalDescription/mods33:form|//mods33:mods/mods33:physicalDescription/mods33:extent|//mods33:mods/mods33:physicalDescription/mods33:reformattingQuality|//mods33:mods/mods33:physicalDescription/mods33:internetMediaType|//mods33:mods/mods33:physicalDescription/mods33:digitalOrigin)$$,
24     TRUE, TRUE, FALSE
25 );
26
27 INSERT INTO config.metabib_field (id, field_class, name, 
28     label, xpath, display_field, search_field, browse_field)
29 VALUES (
30     40, 'identifier', 'publisher', 
31     oils_i18n_gettext(40, 'Publisher', 'cmf', 'label'),
32     $$//mods33:mods/mods33:originInfo//mods33:publisher[1]$$,
33     TRUE, TRUE, FALSE
34 );
35
36 INSERT INTO config.metabib_field (id, field_class, name, 
37     label, xpath, display_field, search_field, browse_field)
38 VALUES (
39     41, 'keyword', 'abstract', 
40     oils_i18n_gettext(41, 'Abstract', 'cmf', 'label'),
41     $$//mods33:mods/mods33:abstract$$,
42     TRUE, TRUE, FALSE
43 );
44
45 INSERT INTO config.metabib_field (id, field_class, name, 
46     label, xpath, display_field, search_field, browse_field)
47 VALUES (
48     42, 'keyword', 'toc', 
49     oils_i18n_gettext(42, 'Table of Contents', 'cmf', 'label'),
50     $$//mods33:tableOfContents$$,
51     TRUE, TRUE, FALSE
52 );
53
54 INSERT INTO config.metabib_field (id, field_class, name, 
55     label, xpath, display_field, search_field, browse_field)
56 VALUES (
57     43, 'identifier', 'type_of_resource', 
58     oils_i18n_gettext(43, 'Type of Resource', 'cmf', 'label'),
59     $$//mods33:mods/mods33:typeOfResource$$,
60     TRUE, FALSE, FALSE
61 );
62
63 INSERT INTO config.metabib_field (id, field_class, name, 
64     label, xpath, display_field, search_field, browse_field)
65 VALUES (
66     44, 'identifier', 'pubdate', 
67     oils_i18n_gettext(44, 'Publication Date', 'cmf', 'label'),
68     $$//mods33:mods/mods33:originInfo//mods33:dateIssued[@encoding="marc"]|//mods33:mods/mods33:originInfo//mods33:dateIssued[1]$$,
69     TRUE, FALSE, FALSE
70 );
71
72 INSERT INTO config.metabib_field (id, field_class, name, 
73     label, xpath, display_field, search_field, browse_field)
74 VALUES (
75     46, 'keyword', 'bibliography', 
76     oils_i18n_gettext(46, 'Bibliography', 'cmf', 'label'),
77     $$//mods33:note[@type='bibliography']$$,
78     TRUE, TRUE, FALSE
79 ),(
80     47, 'keyword', 'thesis', 
81     oils_i18n_gettext(47, 'Thesis', 'cmf', 'label'),
82     $$//mods33:note[@type='thesis']$$,
83     TRUE, TRUE, FALSE
84 ),(
85     48, 'keyword', 'production_credits', 
86     oils_i18n_gettext(48, 'Creation/Production Credits', 'cmf', 'label'),
87     $$//mods33:note[@type='creation/production credits']$$,
88     TRUE, TRUE, FALSE
89 ),(
90     49, 'keyword', 'performers', 
91     oils_i18n_gettext(49, 'Performers', 'cmf', 'label'),
92     $$//mods33:note[@type='performers']$$,
93     TRUE, TRUE, FALSE
94 ),(
95     50, 'keyword', 'general_note', 
96     oils_i18n_gettext(50, 'General Note', 'cmf', 'label'),
97     $$//mods33:note[not(@type)]$$,
98     TRUE, TRUE, FALSE
99 )
100 ;
101
102 INSERT INTO config.metabib_field (id, field_class, name, format,
103     label, xpath, display_xpath, display_field, search_field, browse_field)
104 VALUES (
105     51, 'author', 'first_author', 'mods32',
106     oils_i18n_gettext(51, 'Author', 'cmf', 'label'),
107     $$//mods32:mods/mods32:name[mods32:role/mods32:roleTerm[text()='creator']][1]$$,
108     $$//*[local-name()='namePart']$$,
109     TRUE, TRUE, FALSE
110 );
111
112 INSERT INTO config.metabib_field (id, field_class, name, format,
113     label, xpath, display_xpath, display_field, search_field, browse_field)
114 VALUES (
115     52, 'identifier', 'origin_info', 'marcxml',
116     oils_i18n_gettext(52, 'Origin Info', 'cmf', 'label'),
117     $$//*[@tag='260']$$,
118     $$//*[local-name()='subfield' and contains('abc',@code)]$$,
119     TRUE, FALSE, FALSE
120 );
121
122
123 -- Modify existing config.metabib_field entries
124
125 UPDATE config.metabib_field SET display_field = TRUE WHERE id IN (
126     1,  -- seriestitle
127     11, -- subject_geographic 
128     12, -- subject_name
129     13, -- subject_temporal
130     14, -- subject_topic
131     19, -- ISSN
132     20, -- UPC
133     26  -- TCN
134 );
135
136 -- Map display field names to config.metabib_field entries
137
138 INSERT INTO config.display_field_map (name, field, multi) VALUES 
139     ('series_title',         1, TRUE),
140     ('subject_geographic',  11, TRUE),
141     ('subject_name',        12, TRUE),
142     ('subject_temporal',    13, TRUE),
143     ('subject_topic',       14, TRUE),
144     ('issn',                19, TRUE),
145     ('upc',                 20, TRUE),
146     ('tcn',                 26, FALSE),
147     ('edition',             38, FALSE),
148     ('physical_description',39, TRUE),
149     ('genre',               33, TRUE),
150     ('bibliography',        46, TRUE),
151     ('thesis',              47, TRUE),
152     ('performers',          49, TRUE),
153     ('production_credits',  48, TRUE),
154     ('general_note',        50, TRUE),
155     ('publisher',           52, FALSE),
156     ('abstract',            41, FALSE),
157     ('toc',                 42, FALSE),
158     ('type_of_resource',    43, FALSE),
159     ('pubdate',             44, FALSE)
160 ;
161
162 UPDATE config.display_field_map SET field = 51 WHERE name = 'author';
163
164 -- Add a column to wide-display-entry per well-known field
165
166 DROP VIEW IF EXISTS metabib.wide_display_entry;
167 CREATE VIEW metabib.wide_display_entry AS
168     SELECT 
169         bre.id AS source,
170         COALESCE(mcde_title.value, 'null')::TEXT AS title,
171         COALESCE(mcde_author.value, 'null')::TEXT AS author,
172         COALESCE(mcde_subject_geographic.value, 'null')::TEXT AS subject_geographic,
173         COALESCE(mcde_subject_name.value, 'null')::TEXT AS subject_name,
174         COALESCE(mcde_subject_temporal.value, 'null')::TEXT AS subject_temporal,
175         COALESCE(mcde_subject_topic.value, 'null')::TEXT AS subject_topic,
176         COALESCE(mcde_creators.value, 'null')::TEXT AS creators,
177         COALESCE(mcde_isbn.value, 'null')::TEXT AS isbn,
178         COALESCE(mcde_issn.value, 'null')::TEXT AS issn,
179         COALESCE(mcde_upc.value, 'null')::TEXT AS upc,
180         COALESCE(mcde_tcn.value, 'null')::TEXT AS tcn,
181         COALESCE(mcde_edition.value, 'null')::TEXT AS edition,
182         COALESCE(mcde_physical_description.value, 'null')::TEXT AS physical_description,
183         COALESCE(mcde_publisher.value, 'null')::TEXT AS publisher,
184         COALESCE(mcde_series_title.value, 'null')::TEXT AS series_title,
185         COALESCE(mcde_abstract.value, 'null')::TEXT AS abstract,
186         COALESCE(mcde_toc.value, 'null')::TEXT AS toc,
187         COALESCE(mcde_pubdate.value, 'null')::TEXT AS pubdate,
188         COALESCE(mcde_type_of_resource.value, 'null')::TEXT AS type_of_resource
189     FROM biblio.record_entry bre 
190     LEFT JOIN metabib.compressed_display_entry mcde_title 
191         ON (bre.id = mcde_title.source AND mcde_title.name = 'title')
192     LEFT JOIN metabib.compressed_display_entry mcde_author 
193         ON (bre.id = mcde_author.source AND mcde_author.name = 'author')
194     LEFT JOIN metabib.compressed_display_entry mcde_subject 
195         ON (bre.id = mcde_subject.source AND mcde_subject.name = 'subject')
196     LEFT JOIN metabib.compressed_display_entry mcde_subject_geographic 
197         ON (bre.id = mcde_subject_geographic.source 
198             AND mcde_subject_geographic.name = 'subject_geographic')
199     LEFT JOIN metabib.compressed_display_entry mcde_subject_name 
200         ON (bre.id = mcde_subject_name.source 
201             AND mcde_subject_name.name = 'subject_name')
202     LEFT JOIN metabib.compressed_display_entry mcde_subject_temporal 
203         ON (bre.id = mcde_subject_temporal.source 
204             AND mcde_subject_temporal.name = 'subject_temporal')
205     LEFT JOIN metabib.compressed_display_entry mcde_subject_topic 
206         ON (bre.id = mcde_subject_topic.source 
207             AND mcde_subject_topic.name = 'subject_topic')
208     LEFT JOIN metabib.compressed_display_entry mcde_creators 
209         ON (bre.id = mcde_creators.source AND mcde_creators.name = 'creators')
210     LEFT JOIN metabib.compressed_display_entry mcde_isbn 
211         ON (bre.id = mcde_isbn.source AND mcde_isbn.name = 'isbn')
212     LEFT JOIN metabib.compressed_display_entry mcde_issn 
213         ON (bre.id = mcde_issn.source AND mcde_issn.name = 'issn')
214     LEFT JOIN metabib.compressed_display_entry mcde_upc 
215         ON (bre.id = mcde_upc.source AND mcde_upc.name = 'upc')
216     LEFT JOIN metabib.compressed_display_entry mcde_tcn 
217         ON (bre.id = mcde_tcn.source AND mcde_tcn.name = 'tcn')
218     LEFT JOIN metabib.compressed_display_entry mcde_edition 
219         ON (bre.id = mcde_edition.source AND mcde_edition.name = 'edition')
220     LEFT JOIN metabib.compressed_display_entry mcde_physical_description 
221         ON (bre.id = mcde_physical_description.source 
222             AND mcde_physical_description.name = 'physical_description')
223     LEFT JOIN metabib.compressed_display_entry mcde_publisher 
224         ON (bre.id = mcde_publisher.source AND mcde_publisher.name = 'publisher')
225     LEFT JOIN metabib.compressed_display_entry mcde_series_title 
226         ON (bre.id = mcde_series_title.source AND mcde_series_title.name = 'series_title')
227     LEFT JOIN metabib.compressed_display_entry mcde_abstract 
228         ON (bre.id = mcde_abstract.source AND mcde_abstract.name = 'abstract')
229     LEFT JOIN metabib.compressed_display_entry mcde_toc 
230         ON (bre.id = mcde_toc.source AND mcde_toc.name = 'toc')
231     LEFT JOIN metabib.compressed_display_entry mcde_pubdate 
232         ON (bre.id = mcde_pubdate.source AND mcde_pubdate.name = 'pubdate')
233     LEFT JOIN metabib.compressed_display_entry mcde_type_of_resource 
234         ON (bre.id = mcde_type_of_resource.source 
235             AND mcde_type_of_resource.name = 'type_of_resource')
236 ;
237
238 CREATE OR REPLACE VIEW reporter.old_super_simple_record AS
239 SELECT  r.id,
240     r.fingerprint,
241     r.quality,
242     r.tcn_source,
243     r.tcn_value,
244     evergreen.oils_json_to_text(d.title) AS title,
245     evergreen.oils_json_to_text(d.author) AS author,
246     evergreen.oils_json_to_text(d.publisher) AS publisher,
247     evergreen.oils_json_to_text(d.pubdate) AS pubdate,
248     CASE WHEN d.isbn = 'null'
249         THEN NULL
250         ELSE (SELECT ARRAY(SELECT json_array_elements_text(d.isbn::JSON)))
251     END AS isbn,
252     CASE WHEN d.issn = 'null'
253         THEN NULL
254         ELSE (SELECT ARRAY(SELECT json_array_elements_text(d.issn::JSON)))
255     END AS issn
256   FROM  biblio.record_entry r
257         JOIN metabib.wide_display_entry d ON (r.id = d.source);
258
259 COMMIT;
260