(: : Module: Utility functions for the database at www.risten.no. : : : Functions that are safe with respect to the planned enhancements : to allow multiple terminology collections and dictionaries are marked as such. : : The functions defined thus far are: : : : namespace: "http://www.risten.no/shared/xqueryfactory" : :) module namespace buildquery="http://www.risten.no/shared/xqueryfactory"; declare namespace util="http://exist-db.org/xquery/util"; declare namespace request="http://exist-db.org/xquery/request"; import module namespace ristenutil="http://www.risten.no/shared/util" at "ristenutil.xqm"; (: + | Assemble the query string. Propnouns. + :) declare function buildquery:search-entries ($term as xs:string, $doc as xs:string) as xs:string { let $expr := local:term-expr($term) return local:build-query($expr, $doc) }; (: + | Function from confirmnewlangentry.xq + :) declare function buildquery:confirmnewlangentry ($record as xs:string, $doc as xs:string) as xs:string { let $expr := local:filter-expr($record) return local:build-query($expr, $doc) }; (: + | From editlangentry.xq, editrecord.xq + :) (: declare function buildquery:editlangentry($record as xs:string, $doc as xs:string) as xs:string { return local:build-query($record, $doc) }; :) (: + | From savelangentry.xq, dictrequest.xq + :) declare function buildquery:savelangentry($record as xs:string, $doc as xs:string) as xs:string { let $expr := local:id-filter($record) return local:build-query($expr, $doc) }; (: + | From savenewlangentry.xq + :) declare function buildquery:savenewlangentry($record as xs:string, $doc as xs:string) as xs:string { let $pos := request:get-parameter("pos", "S"), $newRecID := ristenutil:makeTermID($record, $pos), $expr := local:id-filter($newRecID) return local:build-query($expr, $doc) }; (: + | From savenewrecord.xq + :) declare function buildquery:savenewrecord($record as xs:string, $doc as xs:string) as xs:string { let $pos := request:get-parameter("pos", "S"), $newRecID := ristenutil:makeTermID($record, $pos), $expr := concat ("@id &= ", "'", $newRecID, "'") return local:build-query($expr, $doc) }; (: + | From termedit.xq, termrequest.xq + :) declare function buildquery:termedit($record as xs:string, $doc as xs:string) as xs:string { let $expr := local:term-expr($record) return local:build-query($expr, $doc) }; declare function local:build-query($expr as xs:string, $doc as xs:string) as xs:string { let $query := if (contains($expr, "@id")) then concat("for $r in document('", $doc, "')//entry[", $expr, "] return $r") else ( concat("for $r in document('", $doc, "')", $expr," return $r") ) return $query }; declare function local:term-expr($record as xs:string) as xs:string { let $t := concat("'", $record, "'") return concat("@id &= ", $t) }; (: Create filter expression from query term, field and mode :) declare function local:filter-expr($record as xs:string) as xs:string { let $pos := request:get-parameter("pos", "S") let $t := concat("'", $record, "\", $pos, "'") return concat("@id &= ", $t) }; (: + | Create an ID filter expression from query term + :) declare function local:id-filter($record as xs:string) as xs:string { let $t := concat("'", $record, "'") return concat("@id = ", $t) }; declare function buildquery:get-langdoc($lang as xs:string) as xs:string { let $doc := concat('/db/ordbase/terms/SD-terms/terms-',$lang,'.xml') return $doc };