diff software/eXist/webapp/mpdl/lucene/search.xql @ 15:e99964f390e4

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Mon, 29 Aug 2011 17:40:19 +0200
parents d6f528ad5d96
children 7e883ce72fec
line wrap: on
line diff
--- a/software/eXist/webapp/mpdl/lucene/search.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/lucene/search.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -37,25 +37,19 @@
     else if ($queryType = 'fulltextMorphLemma')
     then concat('lemmalemma', $queryStr)
     else ()
-  let $pageBreaks := 
-    if ($mpdlCollectionName = 'archimedes')
-    then $document//pb
-    else if ($mpdlCollectionName = 'echo') 
-    then $document//echo:pb
-    else if ($mpdlCollectionName = 'tei') 
-    then $document//TEI:pb
-    else $document//pb
+  let $pageBreaks := $document//*[name() = 'pb']
   let $luceneParseResult := mpdltext:lucene-parse-query($queryStr)
   let $t := 
     if ($luceneParseResult != '')
     then ()
     else if ($mpdlCollectionName = 'archimedes')
-    then $document//s[ft:query(., $query)]
+    then $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'echo')
-    then $document//echo:s[ft:query(., $query)]
+    then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'tei')
-    then $document//TEI:s[ft:query(., $query)]
-    else $document//s[ft:query(., $query)]
+    then $document//TEI:s[ft:query(., $query)]|$document//TEI:head[ft:query(., $query)]
+    else $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
+    (: else $document//*[name() = 's' or name() = 'head'][ft:query(., $query)]  this would be much slower and would consume too much memory   :)
   let $from := ($pn * $pageSize) - $pageSize + 1
   let $to := $pn * $pageSize
   (: performance improvements: result set of 500 needs 3 sec., result set of 10 needs 0,7 sec.:)
@@ -64,31 +58,39 @@
     where $poss >= $from and $poss <= $to
     return $ss
   let $queryResult :=
-    for $s at $pos in $tempQueryResult
-      let $pnOfS := count($pageBreaks[. << $s])        (: faster: comparison only in pb elements of this document :)
-      let $pb := subsequence($pageBreaks, $pnOfS, 1)
+    for $hit at $pos in $tempQueryResult
+      let $hitType := local-name($hit)
+      let $pnOfHit := count($pageBreaks[. << $hit])        (: faster: comparison only in pb elements of this document :)
+      let $pb := subsequence($pageBreaks, $pnOfHit, 1)
       (: test if sentence surrounds page break; costs 0,1 sec performance :)
-      let $pbPlus1 := subsequence($pageBreaks, $pnOfS + 1, 1)
-      let $sSurroundsPB := 
-        if ($pbPlus1/parent::node() = $s and $pbPlus1 intersect $s/descendant::node())
+      let $pbPlus1 := subsequence($pageBreaks, $pnOfHit + 1, 1)
+      let $hitSurroundsPB := 
+        if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
         then true()
         else false()
-      let $posOfS :=                           (: faster: comparison only in s elements of this document :)
-        if ($mpdlCollectionName = 'archimedes')
-        then count($pb/following::s[. << $s]) + 1
-        else if ($mpdlCollectionName = 'echo')
-        then count($pb/following::echo:s[. << $s]) + 1
-        else if ($mpdlCollectionName = 'tei')
-        then count($pb/following::TEI:s[. << $s]) + 1
-        else count($pb/following::s[. << $s]) + 1
+      let $posOfHit :=           (: faster: comparison only in s or head elements of this document and only in a specific namespace :)
+        if ($mpdlCollectionName = 'archimedes' and $hitType = 's')
+        then count($pb/following::s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'archimedes' and $hitType = 'head')
+        then count($pb/following::head[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'echo' and $hitType = 's')
+        then count($pb/following::echo:s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'echo' and $hitType = 'head')
+        then count($pb/following::echo:head[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'tei' and $hitType = 's')
+        then count($pb/following::TEI:s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'tei' and $hitType = 'head')
+        then count($pb/following::TEI:head[. << $hit]) + 1
+        else count($pb/following::s[. << $hit]) + 1
       let $position := $from - 1 + $pos
       let $resultElem := 
         <hit>
+          <hitType>{$hitType}</hitType>
           <pos>{$position}</pos>
-          <pn>{$pnOfS}</pn>
-          <pos-of-s>{$posOfS}</pos-of-s>
-          <s>{string($s)}</s>
-          <s-surrounds-pb>{$sSurroundsPB}</s-surrounds-pb>
+          <pn>{$pnOfHit}</pn>
+          <hitPos>{$posOfHit}</hitPos>
+          <hitString>{string($hit)}</hitString>
+          <hitSurroundsPB>{$hitSurroundsPB}</hitSurroundsPB>
         </hit>
     return $resultElem
   let $resultSize := count($t)