LP#1067823: Genre links launch subject search
authorMike Rylander <mrylander@gmail.com>
Thu, 15 Oct 2015 21:20:07 +0000 (17:20 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 17 Feb 2016 15:49:42 +0000 (10:49 -0500)
And genres are not subjects.  So now we will index genres in the identifier
class and teach the tpac to build links appropriately.  Genre is herein
defined as data in tags 655 or 659 (as the tpac currently thinks), restricted
to subfields [abvxyz], per LoC documentation.

To test:

[1] Apply the update and run the partial reingest as suggested
    by the upgrade script.
[2] In the public catalog, navigate to a record that has one
    or more 655 fields.  Click on one of the genre links and
    verify that it retrieves records sharing that genre heading.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Andrea Neiman <aneiman@kent.lib.md.us>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.genre-indexing.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/record/subjects.tt2

index ee87ff5..78c4d6c 100644 (file)
@@ -184,6 +184,9 @@ INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath,
 INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, search_field, authority_xpath, browse_field, browse_sort_xpath ) VALUES
     (32, 'series', 'browse', oils_i18n_gettext(32, 'Series Title (Browse)', 'cmf', 'label'), 'mods32', $$//mods32:mods/mods32:relatedItem[@type="series"]/mods32:titleInfo[@type="nfi"]$$, FALSE, '//@xlink:href', TRUE, $$*[local-name() != "nonSort"]$$ );
 
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, browse_field, facet_field, facet_xpath, joiner ) VALUES
+    (33, 'identifier', 'genre', oils_i18n_gettext(33, 'Genre', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='655' or @tag='659']$$, FALSE, TRUE, $$//*[contains('abvxyz',@code)]$$, ' -- ' ); -- /* to fool vim */;
+
 UPDATE config.metabib_field SET joiner = ' -- ' WHERE field_class = 'subject' AND name NOT IN ('name', 'complete');
 
 SELECT SETVAL('config.metabib_field_id_seq', GREATEST(1000, (SELECT MAX(id) FROM config.metabib_field)));
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.genre-indexing.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.genre-indexing.sql
new file mode 100644 (file)
index 0000000..f846288
--- /dev/null
@@ -0,0 +1,7 @@
+BEGIN;
+
+INSERT INTO config.metabib_field ( id, field_class, name, label, format, xpath, browse_field, facet_field, facet_xpath, joiner ) VALUES
+    (33, 'identifier', 'genre', oils_i18n_gettext(33, 'Genre', 'cmf', 'label'), 'marcxml', $$//marc:datafield[@tag='655' or @tag='659']$$, FALSE, TRUE, $$//*[contains('abvxyz',@code)]$$, ' -- ' ); -- /* to fool vim */;
+
+COMMIT;
index fe0df36..5837c9e 100644 (file)
@@ -5,7 +5,10 @@
             xpath => '//*[@tag="600" or @tag="610" or @tag="611" or @tag="630" or @tag="650" or @tag="651"]'
         }, {
             label => l('Genre: '),
-            xpath => '//*[@tag="655"]|//*[@tag="659"]'
+            facet => 'identifier|genre',
+            joiner => ' -- ',
+            xpath => '//*[@tag="655" or @tag="659"]',
+            subfields => '[abvxyz]'
         }, {
             label => l('Topic Heading: '),
             xpath => '//*[@tag="690"]'
@@ -28,7 +31,7 @@
     ];
 
     BLOCK render_subject;
-        xpath = xpath || '//*[starts-with(@tag,"6")]';
+        xpath = s.xpath || '//*[starts-with(@tag,"6")]';
         FOR node IN ctx.marc_xml.findnodes(xpath);
             '<span property="about">';
             all_terms = [];
                    target_field = node.getAttribute('tag');
                    get_linked_880s;
                 END;
+
                 NEXT UNLESS code.match('[a-z]');
+                IF s.subfields; NEXT UNLESS code.match(s.subfields); END;
+
                 IF code.match('[vxyz]'); " &gt; "; END;
+
                 # at this point, we actually have a partial term to use.
-                single_term = subfield.textContent | html;
-                all_terms.push(subfield.textContent.replace('\-', ' ').replace('[#"^$\+,\.:;&|\[\]()]', ''));
-                total_term = all_terms.join(" ").replace('\s+$', '');
-            %]
-<a href="[% mkurl(ctx.opac_root _ '/results', {qtype=>'subject', query=>total_term}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms)) %]" rel="nofollow" vocab="">[% single_term %]</a>
-            [%- END;
+                raw_term = subfield.textContent;
+                single_term = raw_term | html;
+
+                # facets should be used as-is
+                IF !s.facet; raw_term = raw_term.replace('\-', ' ').replace('[#"^$\+,\.:;&|\[\]()]', ''); END;
+
+                all_terms.push(raw_term);
+
+                IF s.facet;
+                    total_term = s.facet _ '[' _ all_terms.join(s.joiner).replace('\s+$', '') _ ']';
+                ELSE;
+                    total_term = all_terms.join(" ").replace('\s+$', '');
+                END;
+
+                %]<a href="[%-
+                       mkurl(ctx.opac_root _ '/results', {qtype=>'subject', query=>total_term}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms))
+                -%]" rel="nofollow" vocab="">[% single_term %]</a>[%-
+
+            END;
             IF all_terms.size; "<br/>"; END;
             FOREACH link880 IN graphics;
                 '<div class="graphic880"' _ link880.dir _ '>';
@@ -63,7 +83,7 @@
 
 [%  BLOCK render_all_subjects;
     FOREACH subj IN subjects;
-        content = PROCESS render_subject(xpath=subj.xpath);
+        content = PROCESS render_subject(s=subj);
         IF content.match('\S');
 %]
         <table class='rdetail_subject'>