Changeset 298
- Timestamp:
- 03/26/10 16:43:58 (14 years ago)
- Location:
- MDService/trunk/xquery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService/trunk/xquery/cmd-model.xql
r292 r298 21 21 $cmd-index, 22 22 $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 ""), 24 25 $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1)) 25 26 return 26 27 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) 28 29 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) 30 31 else if ($operation eq $cmd-model:searchRetrieve) then 31 32 let $cql-query := request:get-parameter("query", "MDGroup/Actors/Actor"), -
MDService/trunk/xquery/cmd-model.xqm
r292 r298 27 27 declare variable $cmd-model:responseFormatJSon as xs:string := "json"; 28 28 declare variable $cmd-model:responseFormatText as xs:string := "text"; 29 30 declare variable $cmd-model:collectionDocName as xs:string := "collection.xml"; 29 31 30 32 declare variable $cmd-model:xmlExt as xs:string := ".xml"; … … 39 41 let $text-count-distinct := count(distinct-values($text-nodes)) 40 42 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}">{ 42 44 if ($depth > 0) then 43 45 for $elname in $subs[. != ''] … … 84 86 return 85 87 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> 87 89 return ($current, $child-results) 88 90 else … … 114 116 115 117 (: 118 Generic get-doc(collection, docname) 119 :) 120 declare 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 (: 116 126 Function for telling wether the result is already available or not. 117 127 :) 118 128 declare function cmd-model:is-result-available($collection as xs:string, $result-ref as xs:string) as xs:boolean { 119 129 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 :) 135 declare 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)) 120 137 }; 121 138 … … 137 154 let $dummy := util:log('debug', fn:concat('Stores ', $type-name, ' in ', $coll-names)) 138 155 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 :) 161 declare 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)(: , ()) :) 139 166 }; 140 167 … … 195 222 }; 196 223 224 225 226 197 227 (: 198 228 Seraliseringsformat. … … 219 249 :) 220 250 declare 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 221 255 let $children := for $collection-item in $collections 222 256 return 223 257 cmd-model:recurse-collections($collection-item, $max-depth) 224 258 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) 260 return 261 cmd-model:serialise-as(cmd-model:get-doc($collections, $cmd-model:collectionDocName), $format) 227 262 }; 228 263 … … 233 268 let $results := util:eval(fn:concat("collection('", xdb:decode($collection), "')", xdb:decode($cql-query), "/ancestor::CMD")), 234 269 $result-count := fn:count($results), 235 $result-seq := subsequence($results, $start-item, $end-item),270 $result-seq := fn:subsequence($results, $start-item, $end-item), 236 271 $seq-count := fn:count($result-seq), 237 272 $result-fragment := 238 <searchRetrieveResponse>239 240 241 242 273 <searchRetrieveResponse> 274 <numberOfRecords>{$result-count}</numberOfRecords> 275 <echoedSearchRetrieveRequest>{$cql-query, $collection, $start-item, $end-item}</echoedSearchRetrieveRequest> 276 <diagnostics>{$seq-count}</diagnostics> 277 <records> 243 278 {$result-seq} 244 245 </searchRetrieveResponse>279 </records> 280 </searchRetrieveResponse> 246 281 247 282 return
Note: See TracChangeset
for help on using the changeset viewer.