From: <jen...@us...> - 2012-01-21 09:24:56
|
Revision: 15710 http://exist.svn.sourceforge.net/exist/?rev=15710&view=rev Author: jenspetersen Date: 2012-01-21 09:24:45 +0000 (Sat, 21 Jan 2012) Log Message: ----------- [tamboti] Moved subject to modsCommon. Fixes to filtering. Modified Paths: -------------- apps/tamboti/modules/mods-common.xql apps/tamboti/modules/search/filters.xql apps/tamboti/themes/default/css/biblio.css apps/tamboti/themes/default/modules/retrieve-mods.xql Modified: apps/tamboti/modules/mods-common.xql =================================================================== --- apps/tamboti/modules/mods-common.xql 2012-01-21 01:34:04 UTC (rev 15709) +++ apps/tamboti/modules/mods-common.xql 2012-01-21 09:24:45 UTC (rev 15710) @@ -1,10 +1,44 @@ module namespace modsCommon="http://exist-db.org/mods/common"; declare namespace mods="http://www.loc.gov/mods/v3"; +declare namespace functx = "http://www.functx.com"; import module namespace config="http://exist-db.org/mods/config" at "../../../modules/config.xqm"; (:~ +: Used to capitalize the first character of $arg. +: @param $arg A string +: @return A string +: @see http://http://www.xqueryfunctions.com/xq/functx_capitalize-first.html +:) +declare function functx:capitalize-first($arg as xs:string?) as xs:string? { + concat(upper-case(substring($arg,1,1)), + substring($arg,2)) +}; + +(:~ +: Used to transform the camel-case names of MODS elements into space-separated words. +: @param $arg A string +: @param $delim A string +: @return A string +: @see http://www.xqueryfunctions.com/xq/functx_camel-case-to-words.html +:) +declare function functx:camel-case-to-words($arg as xs:string?, $delim as xs:string ) as xs:string? { + concat(substring($arg,1,1), replace(substring($arg,2),'(\p{Lu})', concat($delim, '$1'))) +}; + +(:~ +: Used to remove whitespace at the beginning and end of a string. +: @param $arg A string +: @return A string +: @see http://http://www.xqueryfunctions.com/xq/functx_trim.html +:) +declare function functx:trim($arg as xs:string?) as xs:string { + replace(replace($arg,'\s+$',''),'^\s+','') +}; + + +(:~ : The <b>modsCommon:get-short-title</b> function returns : a compact title for list view, for subject in detail view, and for related items in list and detail view. : The function at present seeks to approach the Chicago style. @@ -693,4 +727,105 @@ else () let $nameOrder := doc(concat($config:edit-app-root, '/code-tables/language-3-type-codes.xml'))/code-table/items/item[value eq $language]/nameOrder/string() return $nameOrder -}; \ No newline at end of file +}; + +(:~ +: The <b>modsCommon:format-subjects</b> function returns +: a table-formatted representation of each mods subject. +: The values for topic, geographic, temporal, titleInfo, name, +: genre, hierarchicalGeographic, cartographics, geographicCode, occupation are represented in subtables. +: +: @author Jens Østergaard Petersen +: @param $entry The subject element +: @param $global-transliteration The value set for the transliteration scheme to be used in the record as a whole, set in e:extension +: @param $global-language The string value of mods/language/languageTerm +: @see http://www.loc.gov/standards/mods/userguide/subject.html +: @return $nameOrder The string 'family-given' or the empty string +:) +declare function modsCommon:format-subjects($entry as element(), $global-transliteration as xs:string, $global-language as xs:string) as element()+ { + for $subject in $entry/mods:subject + let $authority := + if ($subject/@authority/string()) + then concat('(', ($subject/@authority/string()), ')') + else () + return + <tr xmlns="http://www.w3.org/1999/xhtml"> + <td class="label subject">Subject {$authority}</td> + <td class="record"> + { + for $item in $subject/mods:*[string-length(functx:trim(.)) gt 0] + let $authority := + if ($item/@authority/string()) + then concat('(', ($item/@authority/string()), ')') + else () + let $encoding := + if ($item/@encoding/string()) + then concat('(', ($item/@encoding/string()), ')') + else () + let $type := + if ($item/@type/string()) + then concat('(', ($item/@type/string()), ')') + else () + return + <table class="subject"> + <tr><td class="sublabel"> + { + replace(functx:capitalize-first(replace($item/name(), 'mods:','')),'Info',''), + $authority, $encoding, $type + } + </td> + { + (: If there is a child. :) + if ($item/mods:*) + then + <td class="subrecord"> + { + (: If it is a name. :) + if ($item/name() eq 'name') + then modsCommon:format-name($item, 1, 'list-first', $global-transliteration, $global-language) + else + (: If it is a titleInfo. :) + if ($item/name() eq 'titleInfo') + then string-join(modsCommon:get-short-title(<titleInfo>{$item}</titleInfo>), '') + else + (: If it is something else, no special rendering takes place. :) + for $subitem in ($item/mods:*) + let $authority := + if ($subitem/@authority/string()) + then concat('(', ($subitem/@authority/string()), ')') + else () + let $encoding := + if ($subitem/@encoding/string()) + then concat('(', ($subitem/@encoding/string()), ')') + else () + let $type := + if ($subitem/@type/string()) + then concat('(', ($subitem/@type/string()), ')') + else () + return + <table> + <tr> + <td class="sublabel"> + {functx:capitalize-first(functx:camel-case-to-words(replace($subitem/name(), 'mods:',''), ' ')), + $authority, $encoding} + </td> + <td> + <td class="subrecord"> + {$subitem/string()} + </td> + </td> + </tr> + </table> + } + </td> + else + if ($item) then + <table><tr><td class="subrecord" colspan="2">{$item/string()}</td></tr></table> + else () + } + </tr> + </table> + } + </td> + </tr> +}; Modified: apps/tamboti/modules/search/filters.xql =================================================================== --- apps/tamboti/modules/search/filters.xql 2012-01-21 01:34:04 UTC (rev 15709) +++ apps/tamboti/modules/search/filters.xql 2012-01-21 09:24:45 UTC (rev 15710) @@ -4,7 +4,7 @@ Returns the list of distinct title words, names, dates, and subjects occurring in the result set. The query is called via AJAX when the user expands one of the headings in the "filter" box. - The title words are derived from the Lucene index. The names rely on names:format-name() and is therefore expensive. + The title words are derived from the Lucene index. The names rely on names:format-name() and are therefore expensive. :) import module namespace names="http://exist-db.org/xquery/biblio/names" at "names.xql"; @@ -48,7 +48,7 @@ (: There is a load problem with setting this variable to the cache each time a facet button is clicked. 10,000 records amount to about 20 MB and several people could easily access this function at the same time. Even if the cache contains too many items and we do not allow it to be processed, it still takes up memory. -The size has been set to 11,000, to accommodate the largest collection. +The size has been set to 13,000, to accommodate the largest collection. If the result set is larger than that, a message is shown. :) let $cached := if ($record-count gt $local:MAX_RECORD_COUNT) @@ -59,11 +59,13 @@ then <ul> { - let $names := distinct-values($cached//mods:name) + let $names := $cached//mods:name + (: Here we count to string values of the name element, not the formatted result. :) + let $names-count := count(distinct-values($names)) return - if (count($names) gt $local:MAX_RESULTS_NAMES) + if ($names-count gt $local:MAX_RESULTS_NAMES) then - <li>There are too many names ({count(distinct-values($names))}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_NAMES}.</li> + <li>There are too many names ({$names-count}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_NAMES}.</li> else if ($record-count gt $local:MAX_RECORD_COUNT) then @@ -73,7 +75,7 @@ for $author in $names return names:format-name($author) - let $distinct := $authors + let $distinct := distinct-values($authors) for $name in $distinct order by upper-case($name) empty greatest return @@ -96,10 +98,11 @@ $cached/mods:relatedItem/mods:part/mods:date ) ) + let $dates-count := count($dates) return - if (count($dates) gt $local:MAX_RESULTS_DATES) + if ($dates-count gt $local:MAX_RESULTS_DATES) then - <li>There are too many dates ({count(distinct-values($dates))}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_DATES}.</li> + <li>There are too many dates ({$dates-count}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_DATES}.</li> else if ($record-count gt $local:MAX_RECORD_COUNT) then @@ -116,13 +119,14 @@ then <ul> { - let $subjects := distinct-values($cached/mods:subject) + let $subjects := distinct-values($cached/mods:subject) + let $subjects-count := count($subjects) return - if (count($subjects) gt $local:MAX_RESULTS_SUBJECTS) + if ($subjects-count gt $local:MAX_RESULTS_SUBJECTS) then - <li>There are too many subjects ({count(distinct-values($subjects))}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_SUBJECTS}.</li> + <li>There are too many subjects ({$subjects-count}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RESULTS_SUBJECTS}.</li> else - if ($record-count gt $local:MAX_RECORD_COUNT) + if ($record-count gt $local:MAX_RECORD_COUNT) then <li>There are too many records ({$record-count}) to process without overloading the server. Please restrict the result set by performing a narrower search. The maximum number is {$local:MAX_RECORD_COUNT}.</li> else @@ -132,7 +136,7 @@ <li><a href="?filter=Subject&value={$subject}&query-tabs=advanced-search-form">{$subject}</a></li> } </ul> - else - if ($type eq 'keywords') + else + if ($type eq 'keywords') then local:keywords($cached, $record-count) else () \ No newline at end of file Modified: apps/tamboti/themes/default/css/biblio.css =================================================================== --- apps/tamboti/themes/default/css/biblio.css 2012-01-21 01:34:04 UTC (rev 15709) +++ apps/tamboti/themes/default/css/biblio.css 2012-01-21 09:24:45 UTC (rev 15710) @@ -612,7 +612,7 @@ padding-right:1em; vertical-align:middle; color:#BBBBBB; - width:5em; + width:20%; } table .biblio-full .host { Modified: apps/tamboti/themes/default/modules/retrieve-mods.xql =================================================================== --- apps/tamboti/themes/default/modules/retrieve-mods.xql 2012-01-21 01:34:04 UTC (rev 15709) +++ apps/tamboti/themes/default/modules/retrieve-mods.xql 2012-01-21 09:24:45 UTC (rev 15710) @@ -41,7 +41,7 @@ replace($arg,concat('^(.*)',$regex,'.*'),'$1') } ; - (:~ +(:~ : Used to transform the camel-case names of MODS elements into space-separated words. : @param : @return @@ -230,86 +230,6 @@ ' and ') }; - -(: ### <subject> begins ### :) - -(: format subject :) -declare function mods:format-subjects($entry as element(), $global-transliteration as xs:string, $global-language as xs:string) { - for $subject in ($entry/mods:subject) - let $authority := - if ($subject/@authority/string()) - then concat('(', ($subject/@authority/string()), ')') - else () - return - <tr xmlns="http://www.w3.org/1999/xhtml"> - <td class="label subject">Subject {$authority}</td> - <td class="record"><table class="subject"> - { - for $item in ($subject/mods:*) - let $authority := - if ($item/@authority/string()) - then concat('(', ($item/@authority/string()), ')') - else () - let $encoding := - if ($item/@encoding/string()) - then concat('(', ($item/@encoding/string()), ')') - else () - let $type := - if ($item/@type/string()) - then concat('(', ($item/@type/string()), ')') - else () - return - <tr><td class="sublabel"> - { - replace(functx:capitalize-first(functx:capitalize-first(functx:camel-case-to-words(replace($item/name(), 'mods:',''), ' '))),'Info',''), - $authority, $encoding, $type - } - </td><td class="subrecord"> - { - (: If there is a child. :) - if ($item/mods:*) - then - (: If it is a name. :) - if ($item/name() eq 'name') - then modsCommon:format-name($item, 1, 'list-first', $global-transliteration, $global-language) - else - (: If it is a titleInfo. :) - if ($item/name() eq 'titleInfo') - (: NB: What if there is more than one titleInfo? Here one steps out of the iteration. :) - then string-join(modsCommon:get-short-title($item/..), '') - else - (: If it is something else, such as topic (caught by $subitem/name()). :) - for $subitem in ($item/mods:*) - let $authority := - if ($subitem/@authority/string()) - then concat('(', ($subitem/@authority/string()), ')') - else () - let $encoding := - if ($subitem/@encoding/string()) - then concat('(', ($subitem/@encoding/string()), ')') - else () - let $type := - if ($subitem/@type/string()) - then concat('(', ($subitem/@type/string()), ')') - else () - return - <table><tr><td class="sublabel"> - {functx:capitalize-first(functx:camel-case-to-words(replace($subitem/name(), 'mods:',''), ' ')), - $authority, $encoding} - </td><td><td class="subrecord"> - {$subitem/string()} - </td></td></tr></table> - else - <table><tr><td class="subrecord" colspan="2">{$item/string()}</td></tr></table> - } - </td></tr> - } - </table></td> - </tr> -}; - -(: ### <subject> ends ### :) - (: ### <extent> begins ### :) (: <extent> belongs to <physicalDescription>, to <part> as a top level element and to <part> under <relatedItem>. @@ -1568,7 +1488,7 @@ (: subject :) (: We assume that there are not many subjects with the first element, topic, empty. :) if (normalize-space($entry/mods:subject[1]/string())) - then mods:format-subjects($entry, $global-transliteration, $global-language) + then modsCommon:format-subjects($entry, $global-transliteration, $global-language) else () , (: identifier :) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |