comparison 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
comparison
equal deleted inserted replaced
16:257f67be5c00 17:7e883ce72fec
46 then $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)] 46 then $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
47 else if ($mpdlCollectionName = 'echo') 47 else if ($mpdlCollectionName = 'echo')
48 then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)] 48 then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
49 else if ($mpdlCollectionName = 'tei') 49 else if ($mpdlCollectionName = 'tei')
50 then $document//TEI:s[ft:query(., $query)]|$document//TEI:head[ft:query(., $query)] 50 then $document//TEI:s[ft:query(., $query)]|$document//TEI:head[ft:query(., $query)]
51 else $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)] 51 else $document//*:s[ft:query(., $query)]|$document//*:head[ft:query(., $query)]
52 (: else $document//*[name() = 's' or name() = 'head'][ft:query(., $query)] this would be much slower and would consume too much memory :) 52 (: else $document//*[name() = 's' or name() = 'head'][ft:query(., $query)] this would be much slower and would consume too much memory :)
53 let $from := ($pn * $pageSize) - $pageSize + 1 53 let $from := ($pn * $pageSize) - $pageSize + 1
54 let $to := $pn * $pageSize 54 let $to := $pn * $pageSize
55 (: performance improvements: result set of 500 needs 3 sec., result set of 10 needs 0,7 sec.:) 55 (: performance improvements: result set of 500 needs 3 sec., result set of 10 needs 0,7 sec.:)
56 let $tempQueryResult := 56 let $tempQueryResult :=
57 for $ss at $poss in $t 57 for $ss at $poss in $t
58 where $poss >= $from and $poss <= $to 58 where $poss >= $from and $poss <= $to
59 return $ss 59 return $ss
60 let $docSentences :=
61 if ($mpdlCollectionName = 'archimedes')
62 then $document//s
63 else if ($mpdlCollectionName = 'echo')
64 then $document//echo:s
65 else if ($mpdlCollectionName = 'tei')
66 then $document//TEI:s
67 else $document//*:s
68 let $docHeads :=
69 if ($mpdlCollectionName = 'archimedes')
70 then $document//head
71 else if ($mpdlCollectionName = 'echo')
72 then $document//echo:head
73 else if ($mpdlCollectionName = 'tei')
74 then $document//TEI:head
75 else $document//*:head
60 let $queryResult := 76 let $queryResult :=
61 for $hit at $pos in $tempQueryResult 77 for $hit at $pos in $tempQueryResult
62 let $hitType := local-name($hit) 78 let $hitType := local-name($hit)
63 let $pnOfHit := count($pageBreaks[. << $hit]) (: faster: comparison only in pb elements of this document :) 79 let $pnOfHit := count($pageBreaks[. << $hit]) (: faster: comparison only in pb elements of this document :)
64 let $pb := subsequence($pageBreaks, $pnOfHit, 1) 80 let $pb := subsequence($pageBreaks, $pnOfHit, 1)
66 let $pbPlus1 := subsequence($pageBreaks, $pnOfHit + 1, 1) 82 let $pbPlus1 := subsequence($pageBreaks, $pnOfHit + 1, 1)
67 let $hitSurroundsPB := 83 let $hitSurroundsPB :=
68 if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node()) 84 if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
69 then true() 85 then true()
70 else false() 86 else false()
71 let $posOfHit := (: faster: comparison only in s or head elements of this document and only in a specific namespace :) 87 let $pageHits :=
72 if ($mpdlCollectionName = 'archimedes' and $hitType = 's') 88 if ($hitType = 's')
73 then count($pb/following::s[. << $hit]) + 1 89 then $docSentences/.[. >> $pb and . << $pbPlus1]
74 else if ($mpdlCollectionName = 'archimedes' and $hitType = 'head') 90 else if ($hitType = 'head')
75 then count($pb/following::head[. << $hit]) + 1 91 then $docHeads/.[. >> $pb and . << $pbPlus1]
76 else if ($mpdlCollectionName = 'echo' and $hitType = 's') 92 else $docSentences/.[. >> $pb and . << $pbPlus1]
77 then count($pb/following::echo:s[. << $hit]) + 1 93 let $posOfHit := count($pageHits/.[. << $hit]) + 1
78 else if ($mpdlCollectionName = 'echo' and $hitType = 'head')
79 then count($pb/following::echo:head[. << $hit]) + 1
80 else if ($mpdlCollectionName = 'tei' and $hitType = 's')
81 then count($pb/following::TEI:s[. << $hit]) + 1
82 else if ($mpdlCollectionName = 'tei' and $hitType = 'head')
83 then count($pb/following::TEI:head[. << $hit]) + 1
84 else count($pb/following::s[. << $hit]) + 1
85 let $position := $from - 1 + $pos 94 let $position := $from - 1 + $pos
86 let $resultElem := 95 let $resultElem :=
87 <hit> 96 <hit>
88 <hitType>{$hitType}</hitType> 97 <hitType>{$hitType}</hitType>
89 <pos>{$position}</pos> 98 <pos>{$position}</pos>
186 (for $attrElem in $metadata 195 (for $attrElem in $metadata
187 let $doc := $attrElem/fn:root() 196 let $doc := $attrElem/fn:root()
188 let $documentUri := document-uri($doc) 197 let $documentUri := document-uri($doc)
189 let $docBase := functx:substring-after-last(functx:substring-before-last(functx:substring-before-last($documentUri, "/"), "/"), "/") 198 let $docBase := functx:substring-after-last(functx:substring-before-last(functx:substring-before-last($documentUri, "/"), "/"), "/")
190 let $metadataElem := mpdl-lucene:getMetadata($docBase, $doc) 199 let $metadataElem := mpdl-lucene:getMetadata($docBase, $doc)
191 let $attrElemName := mpdl-lucene:getElemNameByAttr($docBase, $orderBy) 200 let $attrElemName :=
192 let $orderByElem := mpdl-lucene:getElemDynamic($metadataElem, $attrElemName) (: this costs performance for many result elements :) 201 if ($orderBy = "document")
202 then "document"
203 else mpdl-lucene:getElemNameByAttr($docBase, $orderBy)
204 let $orderByElem :=
205 if ($attrElemName = "document")
206 then util:document-name($doc)
207 else mpdl-lucene:getElemDynamic($metadataElem, $attrElemName) (: this costs performance for many result elements :)
193 let $orderByTemp := lower-case(string-join($orderByElem, ', ')) 208 let $orderByTemp := lower-case(string-join($orderByElem, ', '))
194 order by $orderByTemp 209 order by $orderByTemp
195 return $attrElem) 210 return $attrElem)
196 211
197 return $result 212 return $result
224 then $doc/archimedes/text 239 then $doc/archimedes/text
225 else if ($docBase = 'echo') 240 else if ($docBase = 'echo')
226 then $doc/echo:echo/echo:text 241 then $doc/echo:echo/echo:text
227 else if ($docBase = 'tei') 242 else if ($docBase = 'tei')
228 then $doc/TEI:TEI/TEI:text 243 then $doc/TEI:TEI/TEI:text
229 else () 244 else $doc/*[1]
230 return $result 245 return $result
231 }; 246 };
232 247
233 248
234 (: TODO: performance improvement: each time util:eval is executed :) 249 (: TODO: performance improvement: each time util:eval is executed :)