Index: MDRepository/trunk/xquery/cmd-model.xqm
===================================================================
--- MDRepository/trunk/xquery/cmd-model.xqm	(revision 827)
+++ MDRepository/trunk/xquery/cmd-model.xqm	(revision 830)
@@ -71,7 +71,8 @@
   API function searchRetrieve. 
 :)
-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()* {
-  let $collection := collection($cmd-model:cmdiMirrorPath),
-    $decoded-query := xdb:decode($cql-query),
+declare function cmd-model:search-retrieve($xpath-query as xs:string, $collections as xs:string+, $format as xs:string, $start-item as xs:integer, $end-item as xs:integer) as item()* {
+  let $start-time := fn:current-dateTime(),
+  $collection := collection($cmd-model:cmdiMirrorPath),
+    $decoded-query := xdb:decode($xpath-query),
     $sanitized-query := cmd-model:sanitize-query($decoded-query),
     $results :=
@@ -84,9 +85,13 @@
     $result-seq := fn:subsequence($results, $start-item, $end-item),
     $seq-count := fn:count($result-seq),
+    $end-time := fn:current-dateTime(),
     $result-fragment :=
     <searchRetrieveResponse>
       <numberOfRecords>{$result-count}</numberOfRecords>
-      <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then "Rewritten to descendant-or-self::CMD" else $cql-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
-      <diagnostics>{$seq-count}</diagnostics>
+      <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then "Rewritten to descendant-or-self::CMD" else $xpath-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
+      <extraResponseData>
+      		<returnedRecords>{$seq-count}</returnedRecords>
+      		<duration>{$end-time - $start-time}</duration>
+      </extraResponseData>
       <records>
 	{$result-seq}
Index: MDRepository/trunk/xquery/cmd-test.xml
===================================================================
--- MDRepository/trunk/xquery/cmd-test.xml	(revision 827)
+++ MDRepository/trunk/xquery/cmd-test.xml	(revision 830)
@@ -31,5 +31,5 @@
 	      					import module namespace cmd-model = "http://spraakbanken.gu.se/clarin/xquery/model"
 									at "xmldb:exist:///db/clarin/cmd-model.xqm";
-	      					cmd-model:query-model('Components', '/db/cmdi-mirror', 'xml', 1)
+	      					cmd-model:query-model('Components', 'root', 'xml', 1)
 								</xquery>
 	      		</sequence>
@@ -39,6 +39,17 @@
 		<group name="cmdi-tests-searchRetrieve">
 				<thread name="thread1" connection="con">
-            <sequence repeat="20" description="query imdi resources (no index)">	      
-	      				<xquery collection="/db/cmdi-mirror" query=""></xquery>
+            <sequence repeat="20" description="actual queries on the mdrecords">	      
+	      				<xquery collection="/db/cmdi-mirror" query="">
+	      					import module namespace cmd-model = "http://spraakbanken.gu.se/clarin/xquery/model"
+									at "xmldb:exist:///db/clarin/cmd-model.xqm";
+	      					 cmd-model:search-retrieve("//title[contains(.,'a')]", 'root', 'xml', 1,10)
+	      				</xquery>
+	      				<xquery collection="/db/cmdi-mirror" query="//ft:query(*, <query><term>Language</term></query>)" />
+	      				<xquery collection="/db/cmdi-mirror" query="ft:query(descendant::IsPartOf, <query><term>clarin-at:aac-test-corpus</term></query>)" />
+	      				<xquery collection="/db/cmdi-mirror" query="//idno[.='4197']" />
+	      				<xquery collection="/db/cmdi-mirror" query="//date[.>'1920']" />
+	      				<xquery collection="/db/cmdi-mirror" query="//ResourceType[.='Metadata']" />
+	      				<xquery collection="/db/cmdi-mirror" query="//sourceDesc/biblStruct/monogr/title[contains(.,'rat')]" />
+	      				<xquery collection="/db/cmdi-mirror" query="//CMD/*[.//teiHeader//monogr/title[contains(.,'t')]][.//teiHeader//imprint/date[.>'1930']][.//teiHeader//imprint/date[.<'1935']]" />	      				
 	      		</sequence>
 				</thread>
Index: MDRepository/trunk/xquery/init-cache.xql
===================================================================
--- MDRepository/trunk/xquery/init-cache.xql	(revision 830)
+++ MDRepository/trunk/xquery/init-cache.xql	(revision 830)
@@ -0,0 +1,32 @@
+(: 
+this script executes some long-running queries
+providing basic summaries about the repositories content.
+it is meant to be run once on dataset-changed,
+the results stored in cache 
+:)
+
+import module namespace cmd-model = "http://spraakbanken.gu.se/clarin/xquery/model"
+at "xmldb:exist:///db/clarin/cmd-model.xqm";
+
+let $model-max-depth := 8
+
+(: clear cache :)
+
+(: get-collections :)
+let $dummy1 := cmd-model:get-collections('root', 'xml', 1),
+		$dummy2 := cmd-model:get-collections('root', 'xml', 2)	      					
+		$dummy3 := cmd-model:get-collections('root', 'xml', 3)	      					
+
+(: query-model:)
+
+let $components := cmd-model:query-model('Components', 'root', 'xml', 1)
+
+(: we have to iterate through the result and run the query-model for every child-term of Components; examples:
+		?q=teiHeader&maxdepth=8
+		?q=olac&maxdepth=8
+		?q=TextCorpusProfile&maxdepth=8
+		?q=collection&maxdepth=8
+ :)
+for $comp-name in $components/Terms/Term/Term/@name
+	let $dummy := cmd-model:query-model($comp-name, 'root', 'xml', $model-max-depth)
+
