diff software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/lucene/search.xql @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/lucene/search.xql	Tue Feb 08 15:16:46 2011 +0100
@@ -0,0 +1,40 @@
+xquery version "1.0";
+
+module namespace mpdl-lucene = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/lucene/search"; 
+
+declare namespace ft = "http://exist-db.org/xquery/lucene";
+
+declare function mpdl-lucene:search($docPath, $ftQuery) as node() {
+  let $document := doc($docPath)
+  (: performance reasons: all hits (not only the first 10! ) are passed through the :)
+  (: for loop: so the overhead in each loop has to be minimized :)
+  let $t := $document//s[ft:query(., $ftQuery)]
+  let $tempQueryResult := 
+    for $ss at $poss in $t
+    (: where $poss > 100 and $poss <= 200  :)
+    return $ss
+  let $queryResult :=
+    for $s at $pos in $tempQueryResult
+      let $pnOfS := count($document//pb[. << $s])    (: faster: comparison only in pb elements of this document :)
+      let $posOfS := count($document//pb[$pnOfS]/following::s[. << $s]) + 1    (: faster: comparisonon only in s elements of this document :)
+      let $resultElem := 
+        <hit>
+          <pos>{$pos}</pos>
+          <pn>{$pnOfS}</pn>
+          <pos-of-s>{$posOfS}</pos-of-s>
+          {$s}
+        </hit>
+    return $resultElem
+  let $resultSize := count($queryResult)
+  let $result := 
+        <ft-query>
+          <name>{$ftQuery}</name>
+          <result>
+            <size>{$resultSize}</size>
+            <hits>
+              {$queryResult}
+            </hits>
+          </result>
+        </ft-query>  
+   return $result
+};
\ No newline at end of file