comparison 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
comparison
equal deleted inserted replaced
14:5df60f24e997 15:e99964f390e4
35 if ($queryType = 'fulltext' or $queryType = 'fulltextMorph') 35 if ($queryType = 'fulltext' or $queryType = 'fulltextMorph')
36 then $queryStr 36 then $queryStr
37 else if ($queryType = 'fulltextMorphLemma') 37 else if ($queryType = 'fulltextMorphLemma')
38 then concat('lemmalemma', $queryStr) 38 then concat('lemmalemma', $queryStr)
39 else () 39 else ()
40 let $pageBreaks := 40 let $pageBreaks := $document//*[name() = 'pb']
41 if ($mpdlCollectionName = 'archimedes')
42 then $document//pb
43 else if ($mpdlCollectionName = 'echo')
44 then $document//echo:pb
45 else if ($mpdlCollectionName = 'tei')
46 then $document//TEI:pb
47 else $document//pb
48 let $luceneParseResult := mpdltext:lucene-parse-query($queryStr) 41 let $luceneParseResult := mpdltext:lucene-parse-query($queryStr)
49 let $t := 42 let $t :=
50 if ($luceneParseResult != '') 43 if ($luceneParseResult != '')
51 then () 44 then ()
52 else if ($mpdlCollectionName = 'archimedes') 45 else if ($mpdlCollectionName = 'archimedes')
53 then $document//s[ft:query(., $query)] 46 then $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
54 else if ($mpdlCollectionName = 'echo') 47 else if ($mpdlCollectionName = 'echo')
55 then $document//echo:s[ft:query(., $query)] 48 then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
56 else if ($mpdlCollectionName = 'tei') 49 else if ($mpdlCollectionName = 'tei')
57 then $document//TEI:s[ft:query(., $query)] 50 then $document//TEI:s[ft:query(., $query)]|$document//TEI:head[ft:query(., $query)]
58 else $document//s[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 :)
59 let $from := ($pn * $pageSize) - $pageSize + 1 53 let $from := ($pn * $pageSize) - $pageSize + 1
60 let $to := $pn * $pageSize 54 let $to := $pn * $pageSize
61 (: 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.:)
62 let $tempQueryResult := 56 let $tempQueryResult :=
63 for $ss at $poss in $t 57 for $ss at $poss in $t
64 where $poss >= $from and $poss <= $to 58 where $poss >= $from and $poss <= $to
65 return $ss 59 return $ss
66 let $queryResult := 60 let $queryResult :=
67 for $s at $pos in $tempQueryResult 61 for $hit at $pos in $tempQueryResult
68 let $pnOfS := count($pageBreaks[. << $s]) (: faster: comparison only in pb elements of this document :) 62 let $hitType := local-name($hit)
69 let $pb := subsequence($pageBreaks, $pnOfS, 1) 63 let $pnOfHit := count($pageBreaks[. << $hit]) (: faster: comparison only in pb elements of this document :)
64 let $pb := subsequence($pageBreaks, $pnOfHit, 1)
70 (: test if sentence surrounds page break; costs 0,1 sec performance :) 65 (: test if sentence surrounds page break; costs 0,1 sec performance :)
71 let $pbPlus1 := subsequence($pageBreaks, $pnOfS + 1, 1) 66 let $pbPlus1 := subsequence($pageBreaks, $pnOfHit + 1, 1)
72 let $sSurroundsPB := 67 let $hitSurroundsPB :=
73 if ($pbPlus1/parent::node() = $s and $pbPlus1 intersect $s/descendant::node()) 68 if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
74 then true() 69 then true()
75 else false() 70 else false()
76 let $posOfS := (: faster: comparison only in s elements of this document :) 71 let $posOfHit := (: faster: comparison only in s or head elements of this document and only in a specific namespace :)
77 if ($mpdlCollectionName = 'archimedes') 72 if ($mpdlCollectionName = 'archimedes' and $hitType = 's')
78 then count($pb/following::s[. << $s]) + 1 73 then count($pb/following::s[. << $hit]) + 1
79 else if ($mpdlCollectionName = 'echo') 74 else if ($mpdlCollectionName = 'archimedes' and $hitType = 'head')
80 then count($pb/following::echo:s[. << $s]) + 1 75 then count($pb/following::head[. << $hit]) + 1
81 else if ($mpdlCollectionName = 'tei') 76 else if ($mpdlCollectionName = 'echo' and $hitType = 's')
82 then count($pb/following::TEI:s[. << $s]) + 1 77 then count($pb/following::echo:s[. << $hit]) + 1
83 else count($pb/following::s[. << $s]) + 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
84 let $position := $from - 1 + $pos 85 let $position := $from - 1 + $pos
85 let $resultElem := 86 let $resultElem :=
86 <hit> 87 <hit>
88 <hitType>{$hitType}</hitType>
87 <pos>{$position}</pos> 89 <pos>{$position}</pos>
88 <pn>{$pnOfS}</pn> 90 <pn>{$pnOfHit}</pn>
89 <pos-of-s>{$posOfS}</pos-of-s> 91 <hitPos>{$posOfHit}</hitPos>
90 <s>{string($s)}</s> 92 <hitString>{string($hit)}</hitString>
91 <s-surrounds-pb>{$sSurroundsPB}</s-surrounds-pb> 93 <hitSurroundsPB>{$hitSurroundsPB}</hitSurroundsPB>
92 </hit> 94 </hit>
93 return $resultElem 95 return $resultElem
94 let $resultSize := count($t) 96 let $resultSize := count($t)
95 let $pages := 97 let $pages :=
96 if ($resultSize = 0) 98 if ($resultSize = 0)