xquery version "1.0";
declare namespace util="http://exist-db.org/xquery/util";
declare namespace dc="http://purl.org/dc/elements/1.1/";
declare namespace fn="http://exist-db.org/local-functions";
declare namespace i18n="http://apache.org/cocoon/i18n/2.1";
(: Create filter expression from query term, field and mode :)
declare function fn:filter-expr($record as xs:string) as xs:string
{
let $t := concat("'", $record, "'")
return
concat("@id &= ", $t)
};
(: Assemble the query string :)
declare function fn:build-query($record as xs:string) as xs:string
{
let $expr := fn:filter-expr($record),
$docs := "'/db/ordbase/terms/SD-terms/termcenter.xml'"
return
concat("for $r in document(", $docs, ")//entry[",
$expr, "] return $r")
};
(: Modify/enhance the query results before display:
Main purpose: to add classification labels, and
to remove unwanted senses before display. Does not
work due to limitations in eXist (XIncludes are
not expanded until serialisation time - thus not
available for inspection at this point.
Solution:
Only classification labels added, the sense filtering
is deferred to XSLT processing, when the XIncludes
are available :)
declare function fn:display($hits as node()+)
as element()
{
let $current := item-at($hits, 1),
$top := $current/topicClass/@top,
$mid := $current/topicClass/@mid,
$botm := $current/topicClass/@botm,
$count := count($current/entryref)
return
WARNING: There was an error with this request! Please check with the webmaster. Cause: No request record value.
else let $query := fn:build-query($record), $hits := util:eval( $query ) return if (empty($hits)) thenERROR! Record {$record} not found!
else ( (:Your search query: