diff software/eXist/webapp/mpdl/lucene/search.xql @ 17:7e883ce72fec

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Sep 2011 16:41:15 +0200
parents e99964f390e4
children
line wrap: on
line diff
--- a/software/eXist/webapp/mpdl/lucene/search.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/lucene/search.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -48,7 +48,7 @@
     then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'tei')
     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//*: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
@@ -57,6 +57,22 @@
     for $ss at $poss in $t
     where $poss >= $from and $poss <= $to
     return $ss
+  let $docSentences := 
+    if ($mpdlCollectionName = 'archimedes')
+    then $document//s
+    else if ($mpdlCollectionName = 'echo')
+    then $document//echo:s
+    else if ($mpdlCollectionName = 'tei')
+    then $document//TEI:s
+    else $document//*:s
+  let $docHeads := 
+    if ($mpdlCollectionName = 'archimedes')
+    then $document//head
+    else if ($mpdlCollectionName = 'echo')
+    then $document//echo:head
+    else if ($mpdlCollectionName = 'tei')
+    then $document//TEI:head
+    else $document//*:head
   let $queryResult :=
     for $hit at $pos in $tempQueryResult
       let $hitType := local-name($hit)
@@ -68,20 +84,13 @@
         if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
         then true()
         else false()
-      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 $pageHits := 
+        if ($hitType = 's')
+        then $docSentences/.[. >> $pb and . << $pbPlus1]
+        else if ($hitType = 'head')
+        then $docHeads/.[. >> $pb and . << $pbPlus1]
+        else $docSentences/.[. >> $pb and . << $pbPlus1]
+      let $posOfHit := count($pageHits/.[. << $hit]) + 1
       let $position := $from - 1 + $pos
       let $resultElem := 
         <hit>
@@ -188,8 +197,14 @@
      let $documentUri := document-uri($doc)
      let $docBase := functx:substring-after-last(functx:substring-before-last(functx:substring-before-last($documentUri, "/"), "/"), "/")
      let $metadataElem := mpdl-lucene:getMetadata($docBase, $doc)
-     let $attrElemName := mpdl-lucene:getElemNameByAttr($docBase, $orderBy)
-     let $orderByElem := mpdl-lucene:getElemDynamic($metadataElem, $attrElemName)  (: this costs performance for many result elements   :)
+     let $attrElemName := 
+       if ($orderBy = "document")
+       then "document"
+       else mpdl-lucene:getElemNameByAttr($docBase, $orderBy)
+     let $orderByElem := 
+       if ($attrElemName = "document")
+       then util:document-name($doc)
+       else mpdl-lucene:getElemDynamic($metadataElem, $attrElemName)  (: this costs performance for many result elements   :)
      let $orderByTemp := lower-case(string-join($orderByElem, ', '))
   order by $orderByTemp
    return $attrElem)
 
@@ -225,7 +240,7 @@
     then $doc/echo:echo/echo:text
     else if ($docBase = 'tei')
     then $doc/TEI:TEI/TEI:text
-    else ()
+    else $doc/*[1]
   return $result	
 };