From 9f7b95cdaf7d7ecedb928c96d0127522be9b7e73 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Wed, 15 Jan 2014 15:25:02 -0500 Subject: [PATCH] TPAC: Use indexed subfields only in author search links Addresses LP# 1267231 in which we found that the titles of works in the added author field (such as subfield t) were showing up in the link ahead of the author's birth and death date (if applicable). Now we reserve the link for only the indexed author subfields (depends on whether the name is personal, corporate, or conference, but generally subfields a/b/c/d/e/n/q), then the extra subfields go after the name + dates, then we finally put the relationship into the parentheses after everything else. We also simplify the markup so that each name is contained in a single element to make it easier to control the layout. Signed-off-by: Dan Scott Signed-off-by: Ben Shum --- .../src/templates/opac/parts/record/authors.tt2 | 103 ++++++++++++++------- 1 file changed, 70 insertions(+), 33 deletions(-) diff --git a/Open-ILS/src/templates/opac/parts/record/authors.tt2 b/Open-ILS/src/templates/opac/parts/record/authors.tt2 index 676e0f855b..c8e56784d2 100644 --- a/Open-ILS/src/templates/opac/parts/record/authors.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/authors.tt2 @@ -23,19 +23,32 @@ authors = [ } ]; +BLOCK normalize_qterm; + subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' '); +END; + +BLOCK normalize_authors; + link_term = link_term _ ' ' _ sf; + sf_raw = PROCESS normalize_qterm; + qterm = qterm _ ' ' _ sf_raw; + indexed_term = 1; +END; + BLOCK build_author_links; FOR node IN ctx.marc_xml.findnodes(xpath); author_cnt = author_cnt + 1; contrib_ref = '#schemacontrib' _ author_cnt; - iprop = ''; - term = ''; - qterm = ''; + iprop = ''; # schema.org item type / property + link_term = ''; # Linked term (e.g. Personal name + Fuller form of name) + supp_term = ''; # Supplementary terms + qterm = ''; # Search query tlabel = ''; birthdate = ''; deathdate = ''; graphics = []; tag = node.getAttribute('tag'); FOR subfield IN node.childNodes; + indexed_term = ''; NEXT UNLESS subfield.nodeName == "subfield"; code = subfield.getAttribute('code'); IF code == '4'; @@ -49,23 +62,36 @@ BLOCK build_author_links; END; NEXT UNLESS code.match('[a-z]'); sf = subfield.textContent | html; - IF code.match('[acdq]'); - sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' '); - qterm = qterm _ ' ' _ sf_raw; - END; + # Only Persons have birth/death dates in schema.org - IF code.match('d') && tag.substr(1,2) == '00'; - IF subfield.textContent.match('^\s*\d{4}'); - birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1'); + # Match personal/corporate/conference MODS subfields + IF tag.substr(1,2) == '00'; + IF code.match('[abcqu]'); + PROCESS normalize_authors; END; - IF subfield.textContent.match('-\d{4}.*$'); - deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1'); + IF code.match('d'); + IF subfield.textContent.match('^\s*\d{4}'); + birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1'); + END; + IF subfield.textContent.match('-\d{4}.*$'); + deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1'); + END; + indexed_term = 1; + sf_raw = PROCESS normalize_qterm; + qterm = qterm _ sf_raw; END; - ELSE; - term = term _ ' ' _ sf; + ELSIF tag.substr(1,2) == '10'; + IF code.match('[abcdn]'); + PROCESS normalize_authors; + END; + ELSIF code.match('[acdeq]'); + PROCESS normalize_authors; + END; + UNLESS indexed_term; + supp_term = supp_term _ ' ' _ sf; END; END; - url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, stop_parms.merge(expert_search_parms, general_search_parms)); + url = mkurl(ctx.opac_root _ '/results', {query => qterm.replace('^\s*(.*?)\s*$', '$1'), qtype => 'author'}, stop_parms.merge(expert_search_parms, general_search_parms)); author_type = (tlabel || label) | html; # schema.org changes @@ -79,33 +105,41 @@ BLOCK build_author_links; END; ELSIF type == 'added'; IF tag.substr(1,2) == '00'; - iprop = ' typeOf="Person" property="contributor"'; + iprop = ' typeof="Person" property="contributor"'; ELSE; - iprop = ' typeOf="Organization" property="contributor"'; + iprop = ' typeof="Organization" property="contributor"'; END; END; - ''; - IF iprop; ''; END; - term.replace('^\s+', ''); - IF iprop; ''; END; + authtml = ' '; + IF iprop; authtml = authtml _ ''; END; + authtml = authtml _ link_term.replace('^\s+', ''); + IF iprop; authtml = authtml _ ''; END; IF birthdate; - ' ' _ birthdate _ '-'; + authtml = authtml _ ' ' _ birthdate _ '-'; END; IF deathdate; - '' _ deathdate _ ''; + authtml = authtml _ '' _ deathdate _ ''; + END; + authtml = authtml _ ''; # End search link + + # Display supplemental terms (mostly about the author's work) + IF supp_term; + authtml = authtml _ ' ' _ supp_term; END; - ''; # End search link + + # Display linked 880 fields FOREACH link880 IN graphics; diratt = ''; IF link880.dir; diratt = ' dir="' _ link880.dir _ '"'; END; - ' '; + authtml = authtml _ ' '; link880.value | html; - ''; + authtml = authtml _ ''; END; - ' (' _ author_type _ '). '; - ''; # End author span + authtml = authtml _ ' (' _ author_type _ '). '; + authtml = authtml _ ''; # End author span + authlist.push(authtml); END; END; %] @@ -113,13 +147,16 @@ END;
[%- FOREACH author IN authors; NEXT UNLESS author.xpath; - links = PROCESS build_author_links( + authlist = []; + PROCESS build_author_links( xpath=author.xpath, label=author.label, type=author.type ); - IF links.match('\S') %] - [% links %] - [%- END %] -[%- END %] + IF authlist.size; + FOREACH authtml IN authlist; + authtml; + END; + END; +END %]
-- 2.11.0