Changeset 298 for MDService


Ignore:
Timestamp:
03/26/10 16:43:58 (14 years ago)
Author:
ljo
Message:

First round of searchRetrieve results.

Location:
MDService/trunk/xquery
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • MDService/trunk/xquery/cmd-model.xql

    r292 r298  
    2121      $cmd-index,
    2222    $format := request:get-parameter("format", $cmd-model:responseFormatXml),
    23     $collection := fn:concat("/db/cmdi-mirror/", request:get-parameter("collection", "silang_data")),
     23    $collection := "/db/cmdi-mirror",
     24    $query-model-collection := fn:concat($collection, "/", if (fn:empty(request:get-parameter("collection", ()))) then "silang_data" else ""),
    2425    $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1))
    2526    return
    2627      if ($operation eq $cmd-model:getCollections) then
    27         cmd-model:get-collections($collection, $format, $max-depth)
     28        cmd-model:get-collections(fn:concat($collection, if (fn:empty(request:get-parameter("collection", ()))) then "" else fn:concat("/", request:get-parameter("collection", ())), $format, $max-depth)
    2829      else if ($operation eq $cmd-model:queryModel) then
    29         cmd-model:query-model($cmd-index-path, $collection, $format, $max-depth)
     30        cmd-model:query-model($cmd-index-path, $query-model-collection, $format, $max-depth)
    3031    else if ($operation eq $cmd-model:searchRetrieve) then
    3132      let $cql-query := request:get-parameter("query", "MDGroup/Actors/Actor"),
  • MDService/trunk/xquery/cmd-model.xqm

    r292 r298  
    2727declare variable $cmd-model:responseFormatJSon as xs:string := "json";
    2828declare variable $cmd-model:responseFormatText as xs:string := "text";
     29
     30declare variable $cmd-model:collectionDocName as xs:string := "collection.xml";
    2931
    3032declare variable $cmd-model:xmlExt as xs:string := ".xml";
     
    3941  let $text-count-distinct := count(distinct-values($text-nodes))
    4042  return
    41         <Term path="{fn:concat("//", $path)}" count="{$path-count}" count_text="{$text-count}"  count_distinct_text="{$text-count-distinct}">{
     43        <Term path="{fn:concat("//", $path)}" name="{text:groups($path, "/([^/]+)$")[last()]}" count="{$path-count}" count_text="{$text-count}"  count_distinct_text="{$text-count-distinct}">{
    4244          if ($depth > 0) then
    4345            for $elname in $subs[. != '']
     
    8486            return
    8587              cmd-model:recurse-collections(concat($collection, '/', xs:string($child)), $depth),
    86               $current := <Collection>{$collection}</Collection>
     88              $current := <Collection name="{text:groups($collection, "/([^/]+)$")[last()]}">{$collection}</Collection>
    8789          return ($current, $child-results)
    8890      else
     
    114116
    115117(:
     118 Generic get-doc(collection, docname)
     119:)
     120declare function cmd-model:get-doc($collection as xs:string, $doc-name as xs:string) as item()* {
     121      fn:doc(fn:concat($collection, "/", $doc-name))
     122};
     123
     124
     125(:
    116126  Function for telling wether the result is already available or not.
    117127:)
    118128declare function cmd-model:is-result-available($collection as xs:string, $result-ref as xs:string) as xs:boolean {
    119129  fn:doc-available(fn:concat($collection, $result-ref, $cmd-model:xmlExt))
     130};
     131
     132(:
     133  Function for telling wether the document is available or not.
     134:)
     135declare function cmd-model:is-doc-available($collection as xs:string, $doc-name as xs:string) as xs:boolean {
     136  fn:doc-available(fn:concat($collection, "/", $doc-name))
    120137};
    121138
     
    137154        let $dummy := util:log('debug', fn:concat('Stores ', $type-name, ' in ', $coll-names))
    138155        return xdb:store($coll-names, cmd-model:make-doc-name($coll-names, $type-name, xs:string($depth), fn:false()), cmd-model:make-doc-element-of-type($type-name, (), $entries, xs:string($depth)))
     156};
     157
     158(:
     159  Store the collection listing in give collection.
     160:)
     161declare function cmd-model:store-collection-data($data as node(), $collection-path as xs:string) as xs:string? {
     162  let $clarin-writer := fn:doc("/db/clarin/writer.xml"),
     163  $dummy := xdb:login($cmd-model:cmdiDatabaseURI, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text())
     164  return
     165      (: util:catch("org.exist.xquery.XPathException", :) xdb:store($collection-path, $cmd-model:collectionDocName, $data)(: , ()) :)
    139166};
    140167
     
    195222};
    196223
     224
     225
     226
    197227(:
    198228  Seraliseringsformat.
     
    219249:)
    220250declare 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    ()
     254  else
    221255  let $children := for $collection-item in $collections
    222256                    return
    223257                      cmd-model:recurse-collections($collection-item, $max-depth)
    224258   return
    225      cmd-model:serialise-as(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $format)
    226 
     259     cmd-model:store-collection-data(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $collections)
     260return
     261cmd-model:serialise-as(cmd-model:get-doc($collections, $cmd-model:collectionDocName), $format)
    227262};
    228263
     
    233268  let $results := util:eval(fn:concat("collection('", xdb:decode($collection), "')", xdb:decode($cql-query), "/ancestor::CMD")),
    234269    $result-count := fn:count($results),
    235     $result-seq := subsequence($results, $start-item, $end-item),
     270    $result-seq := fn:subsequence($results, $start-item, $end-item),
    236271    $seq-count := fn:count($result-seq),
    237272    $result-fragment :=
    238 <searchRetrieveResponse>
    239         <numberOfRecords>{$result-count}</numberOfRecords>
    240         <echoedSearchRetrieveRequest>{$cql-query, $collection, $start-item, $end-item}</echoedSearchRetrieveRequest>
    241         <diagnostics>{$seq-count}</diagnostics>
    242         <records>
     273    <searchRetrieveResponse>
     274      <numberOfRecords>{$result-count}</numberOfRecords>
     275      <echoedSearchRetrieveRequest>{$cql-query, $collection, $start-item, $end-item}</echoedSearchRetrieveRequest>
     276      <diagnostics>{$seq-count}</diagnostics>
     277      <records>
    243278        {$result-seq}
    244         </records>
    245 </searchRetrieveResponse>
     279      </records>
     280    </searchRetrieveResponse>
    246281
    247282    return
Note: See TracChangeset for help on using the changeset viewer.