Changeset 570 for MDRepository


Ignore:
Timestamp:
07/05/10 15:35:36 (14 years ago)
Author:
ljo
Message:

cmd-model.xqm - handle several collections consistently for get-collection and search-retrieve.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDRepository/trunk/xquery/cmd-model.xqm

    r301 r570  
    159159  Store the collection listing in give collection.
    160160:)
    161 declare function cmd-model:store-collection-data($data as node(), $collection-path as xs:string) as xs:string? {
     161declare function cmd-model:store-collection-data($data as node(), $collection-path as xs:string, $doc-name as xs:string) as xs:string? {
    162162  let $clarin-writer := fn:doc("/db/clarin/writer.xml"),
    163163  $dummy := xdb:login($cmd-model:cmdiDatabaseURI, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text())
    164164  return
    165       (: util:catch("org.exist.xquery.XPathException", :) xdb:store($collection-path, $cmd-model:collectionDocName, $data)(: , ()) :)
     165      (: util:catch("org.exist.xquery.XPathException", :) xdb:store($collection-path, $doc-name, $data)(: , ()) :)
    166166};
    167167
     
    249249:)
    250250declare function cmd-model:get-collections($collections as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() {
    251   (: fixme! - collections, is-doc-available only takes one collection.:)
    252   let $dummy := if (cmd-model:is-doc-available($collections, $cmd-model:collectionDocName)) then
    253     ()
     251  let $names := if (exists($collections[2])) then
     252    ($cmd-model:commonFreqsPath, cmd-model:make-compound-doc-name($collections, "collection", $max-depth))
    254253  else
    255   let $children := for $collection-item in $collections
    256                     return
    257                       cmd-model:recurse-collections($collection-item, $max-depth)
    258    return
    259      cmd-model:store-collection-data(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $collections)
     254    ($collections, $cmd-model:collectionDocName),
     255 $dummy :=   
     256      if (cmd-model:is-doc-available($names[1], $names[2])) then
     257        ()
     258      else
     259        let $children := for $collection-item in $collections
     260        return
     261          cmd-model:recurse-collections($collection-item, $max-depth)
     262          return
     263            cmd-model:store-collection-data(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $names[1], $names[2])
    260264return
    261 cmd-model:serialise-as(cmd-model:get-doc($collections, $cmd-model:collectionDocName), $format)
     265  cmd-model:serialise-as(cmd-model:get-doc($names[1], $names[2]), $format)
    262266};
    263267
     
    266270:)
    267271declare function cmd-model:search-retrieve($cql-query as xs:string, $collection as xs:string+, $format as xs:string, $start-item as xs:integer, $end-item as xs:integer) as item()* {
    268   let $results := util:eval(fn:concat("collection('", xdb:decode($collection), "')", xdb:decode($cql-query), "/ancestor::CMD")),
     272  let $results := for $coll in $collection return util:eval(fn:concat("collection('", xdb:decode($coll), "')", xdb:decode($cql-query), "/ancestor::CMD")),
    269273    $result-count := fn:count($results),
    270274    $result-seq := fn:subsequence($results, $start-item, $end-item),
Note: See TracChangeset for help on using the changeset viewer.