Changeset 826 for MDRepository
- Timestamp:
- 11/01/10 13:24:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDRepository/trunk/xquery/cmd-model.xqm
r825 r826 42 42 declare function cmd-model:query-model($cmd-index-path as xs:string, $collection as xs:string+, $format as xs:string, $max-depth as xs:integer) as item()? { 43 43 44 45 44 let $name := cmd-model:gen-cache-id("model", ($collection, $cmd-index-path), xs:string($max-depth)), 45 $doc := 46 46 if (cmd-model:is-in-cache($name)) then 47 47 cmd-model:get-from-cache($name) 48 48 else 49 let $data := cmd-model:elem($collection, $cmd-index-path, $max-depth) 50 return cmd-model:store-in-cache($name, $data) 51 52 return 53 cmd-model:serialise-as($doc, $format) 49 let $data := cmd-model:elem($collection, $cmd-index-path, $max-depth) 50 return cmd-model:store-in-cache($name, $data) 51 return 52 cmd-model:serialise-as($doc, $format) 54 53 }; 55 54 … … 59 58 declare function cmd-model:get-collections($collections as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() { 60 59 let $name := cmd-model:gen-cache-id("collection", $collections, xs:string($max-depth)), 61 60 $doc := 62 61 if (cmd-model:is-in-cache($name)) then 63 62 cmd-model:get-from-cache($name) 64 63 else 65 66 67 68 64 let $data := cmd-model:colls($collections, $max-depth) 65 return cmd-model:store-in-cache($name, $data) 66 return 67 cmd-model:serialise-as($doc, $format) 69 68 }; 70 69 … … 74 73 declare function cmd-model:search-retrieve($cql-query as xs:string, $collections as xs:string+, $format as xs:string, $start-item as xs:integer, $end-item as xs:integer) as item()* { 75 74 let $collection := collection($cmd-model:cmdiMirrorPath), 75 $decoded-query := xdb:decode($cql-query), 76 $sanitized-query := cmd-model:sanitize-query($decoded-query), 76 77 $results := 77 78 if ($collections[1] eq $cmd-model:collectionRoot) then 78 util:eval(fn:concat("$collection", xdb:decode($cql-query), "/ancestor::CMD"))79 util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD")) 79 80 else 80 for $coll in $collections return util:eval(fn:concat("$collection", xdb:decode($cql-query), "/ancestor::CMD[descendant::IsPartOf = '", xdb:decode($coll) ,"']"))81 for $coll in $collections return util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD[descendant::IsPartOf = '", xdb:decode($coll) ,"']")) 81 82 82 83 let $result-count := fn:count($results), … … 86 87 <searchRetrieveResponse> 87 88 <numberOfRecords>{$result-count}</numberOfRecords> 88 <echoedSearchRetrieveRequest>{ $cql-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>89 <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then "Rewritten to descendant-or-self::CMD" else $cql-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest> 89 90 <diagnostics>{$seq-count}</diagnostics> 90 91 <records> … … 98 99 }; 99 100 100 (: ********************** 101 queryModel - subfunctions 102 C:) 101 (: 102 ********************** 103 queryModel - subfunctions 104 :) 105 106 declare function cmd-model:sanitize-query($query as xs:string) as xs:string { 107 if ($query = ("//*", "descendant::element()")) then "/descendant-or-self::CMD" else $query 108 }; 103 109 104 110 declare function cmd-model:elem($collections as xs:string+, $path as xs:string, $depth as xs:integer) as element() { … … 156 162 157 163 158 (: ********************** 159 getCollections - subfunctions :) 164 (: 165 ********************** 166 getCollections - subfunctions 167 :) 160 168 161 169 declare function cmd-model:colls($collections as xs:string+, $max-depth as xs:integer) as element() { … … 208 216 }; 209 217 210 (: Get the next level collection-records (ResourceType='Metadata') 218 (: 219 Get the next level collection-records (ResourceType='Metadata') 211 220 rely on the ResourceProxy of the parent (param) 212 221 :) … … 218 227 }; 219 228 220 (: count ALL (independent of maxDepth) resource-records (ie actually ResourceType=Resource, but 221 there are records without ResourceProxy[ResourceType=Resource] - so care for that (not(exists((ResourceType)))) 229 (: 230 count ALL (independent of maxDepth) resource-records (ie actually ResourceType=Resource, but 231 there are records without ResourceProxy[ResourceType=Resource] - 232 so care for that (not(exists((ResourceType)))) 222 233 :) 223 234 declare function cmd-model:get-resource-count($handle as xs:string) as xs:string { … … 225 236 }; 226 237 227 (: this is complement to cmd-model:get-resource-count() 228 count ALL (independent of maxDepth) collection-records (ie ResourceType=Metadata 238 (: 239 This is complement to cmd-model:get-resource-count() 240 count ALL (independent of maxDepth) collection-records 241 (ie ResourceType=Metadata) 229 242 :) 230 243 declare function cmd-model:get-collection-count($handle as xs:string) as xs:string { … … 232 245 }; 233 246 234 (: Try to derive a name from the collection-record (more-or-less agnostic about the actual schema. 247 (: 248 Try to derive a name from the collection-record (more-or-less agnostic about 249 the actual schema. 235 250 :) 236 251 declare function cmd-model:get-md-collection-name($collection-doc as node()) as xs:string { … … 238 253 }; 239 254 240 (: *********************** 241 HELPER function - dealing with caching the results 242 :) 243 244 245 (: Function for telling wether the document is available or not. 246 generic, currently not used 255 (: 256 *********************** 257 HELPER function - dealing with caching the results 258 :) 259 260 261 (: 262 Function for telling wether the document is available or not. 263 generic, currently not used 247 264 :) 248 265 declare function cmd-model:is-doc-available($collection as xs:string, $doc-name as xs:string) as xs:boolean { … … 295 312 $item 296 313 }; 297
Note: See TracChangeset
for help on using the changeset viewer.