bib record subject search terms: painstaking translation of BibTemplate to TT
authorsenator <lebbeous@esilibrary.com>
Tue, 15 Mar 2011 19:16:23 +0000 (15:16 -0400)
committersenator <lebbeous@esilibrary.com>
Tue, 15 Mar 2011 19:16:23 +0000 (15:16 -0400)
the reference implementation I used is in
Open-ILS/web/opac/skin/default/xml/rdetail/rdetail_summary.xml starting
at line 93 as of this commit.

Only now that I've imitated the default skin's behavior exactly, I note
that the subject search links produced don't actually work on my test server.
Seems to be a local configuration issue though; will investigate.

Open-ILS/web/templates/default/opac/parts/record/summary.tt2

index 9a6ed0b..ab4da64 100644 (file)
                             </td>
                             <td valign="top" id='rdetail_publisher'>[% attrs.publisher %]</td>
                             [% BLOCK render_subject;
-                            FOR node IN ctx.marc_xml.findnodes('//*[@tag="650"]');
-                                s0 = node.childNodes.0.textContent;
-                                s1 = node.childNodes.1.textContent;
-                                IF s0;
-                                    IF s0.match('\S') %]
-                                    <a href="[% ctx.opac_root %]/results?query=su:[% s0 | url %]">[% s0 %]</a>
-                                    &mdash;
-                                    [% END; IF s1 %]
-                                    <a href="[% ctx.opac_root %]/results?query=su:[% s1 | url %]">[% s1 %]</a>
-                                    <br/>
-                                    [% END %]
-                                [% END %]
-                            [% END %]
+                            loc = CGI.param('loc') | uri;
+                            FOR node IN ctx.marc_xml.findnodes('//*[starts-with(@tag,"6")]');
+                                all_terms = [];
+                                FOR subfield IN node.childNodes;
+                                    NEXT UNLESS subfield.nodeName == "subfield";
+                                    code = 0;
+                                    FOR a IN subfield.attributes;
+                                        IF a.nodeName == "code";
+                                            code = a.nodeValue;
+                                        END;
+                                    END;
+                                    NEXT UNLESS code.match('[a-z]');
+
+                                    IF code.match('[vxyz]');
+                                        " &mdash; ";
+                                    END;
+                                    # at this point, we actually have a partial
+                                    # term to use.
+                                    single_term = subfield.textContent | html;
+                                    all_terms.push(subfield.textContent);
+                                    total_term = all_terms.join(" ").replace('\s+$', '') ; # XXX need to take care of any &'s, right?
+                                    '<a href="' _ ctx.opac_root _ '/results?qtype=subject&query=' _ total_term _ '&loc=' _ loc _ '">' _ single_term _ '</a>';
+                                END;
+                                "<br />";
+                            END %]
                             [% END %]
                             [% s = PROCESS render_subject; IF s.match('\S') %]
                             <td nowrap='nowrap' valign="top">