Mercurial > hg > mpdl-group
comparison software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/page-query-result.xquery.old.xquery @ 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 |
comparison
equal
deleted
inserted
replaced
6:2396a569e446 | 7:5589d865af7a |
---|---|
1 xquery version "1.0"; | |
2 | |
3 module namespace ft="http://exist-db.org/xquery/lucene"; | |
4 declare namespace request="http://exist-db.org/xquery/request"; | |
5 declare namespace text="http://exist-db.org/xquery/text"; | |
6 declare namespace transform="http://exist-db.org/xquery/transform"; | |
7 declare namespace util="http://exist-db.org/xquery/util"; | |
8 declare namespace docc = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/docc"; | |
9 declare namespace time-util = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/time-util"; | |
10 | |
11 declare function time-util:duration-as-ms($t) { | |
12 round((minutes-from-duration($t) * 60 + seconds-from-duration($t)) * 1000 ) | |
13 }; | |
14 | |
15 declare function docc:ft-search($docPath, $ftQuery) as node() { | |
16 let $document := doc($docPath) | |
17 (: performance reasons: all hits (not only the first 10! ) are passed through the :) | |
18 (: for loop: so the overhead in each loop has to be minimized :) | |
19 let $t := $document//s[ft:query(., $ftQuery)] | |
20 let $tempQueryResult := | |
21 for $ss at $poss in $t | |
22 (: where $poss > 100 and $poss <= 200 :) | |
23 return $ss | |
24 let $queryResult := | |
25 for $s at $pos in $tempQueryResult | |
26 let $pnOfS := count($document//pb[. << $s]) (: faster: comparison only in pb elements of this document :) | |
27 let $posOfS := count($document//pb[$pnOfS]/following::s[. << $s]) + 1 (: faster: comparisonon only in s elements of this document :) | |
28 let $resultElem := | |
29 <hit> | |
30 <pos>{$pos}</pos> | |
31 <pn>{$pnOfS}</pn> | |
32 <pos-of-s>{$posOfS}</pos-of-s> | |
33 {$s} | |
34 </hit> | |
35 return $resultElem | |
36 let $resultSize := count($queryResult) | |
37 let $result := | |
38 <ft-query> | |
39 <name>{$ftQuery}</name> | |
40 <result> | |
41 <size>{$resultSize}</size> | |
42 <hits> | |
43 {$queryResult} | |
44 </hits> | |
45 </result> | |
46 </ft-query> | |
47 return $result | |
48 }; | |
49 | |
50 declare function docc:termEntries($term as xs:string, $data as xs:int+) { | |
51 let $result := | |
52 <entry> | |
53 <term>{$term}</term> | |
54 <frequency>{$data[1]}</frequency> | |
55 <documents>{$data[2]}</documents> | |
56 <position>{$data[3]}</position> | |
57 <rank>{$data[4]}</rank> | |
58 </entry> | |
59 return $result | |
60 }; | |
61 | |
62 declare function docc:indexTerms($document, $indexTermsStartStr, $count) as node()* { | |
63 let $docName := util:document-name($document) | |
64 let $index := /archimedes/info/cvs_file[contains(., $docName)]/root()/archimedes/text | |
65 let $callback := util:function(QName("http://www.mpiwg-berlin.mpg.de/ns/mpdl/docc", "docc:termEntries"), 2) | |
66 let $result := text:index-terms($index, $indexTermsStartStr, $callback, $count) | |
67 return | |
68 <index-terms> | |
69 <start-string>{$indexTermsStartStr}</start-string> | |
70 {$result} | |
71 </index-terms> | |
72 }; | |
73 | |
74 | |
75 let $document := request:get-parameter("document", "agric_remet_001_la_1556") | |
76 let $mode := request:get-parameter("mode", "image") | |
77 let $pn := number(request:get-parameter("pn", "1")) | |
78 let $ftQuery := request:get-parameter("ft-query", "") | |
79 let $indexTermsStartStr := request:get-parameter("index-terms-start-str", "") | |
80 | |
81 let $currentTimeBegin := util:system-time() | |
82 let $docPath := concat("/db/archimedes/", $document, ".xml") | |
83 let $docRoot := doc($docPath) | |
84 let $archimedesInfo := $docRoot/archimedes/info | |
85 let $locator := $archimedesInfo/locator | |
86 let $countPages := count($docRoot//pb) | |
87 let $pb1 := $docRoot//pb[$pn] | |
88 let $positionOfFirstFigureAfterPB1 := count($pb1/following::figure[1]/preceding::figure) + 1 (: position der ersten figure nach pb1 :) | |
89 let $pb1ImageRefLeft := substring-before($locator, ".") | |
90 let $pb1ImageRefRight := "01" | |
91 let $pb2 := $docRoot//pb[$pn + 1] | |
92 let $errorCode := | |
93 if ($pn < $countPages + 1 and $pn > 0) | |
94 then 0 | |
95 else 1 | |
96 | |
97 let $retPageFragment := | |
98 if ($mode = "image" or $errorCode > 0) | |
99 then () | |
100 else util:get-fragment-between($pb1, $pb2, true()) | |
101 | |
102 let $returnPageFragment := util:parse($retPageFragment) (: string2xml: returns a valid xml document for that string :) | |
103 | |
104 let $ftHits := | |
105 if ($ftQuery = "") | |
106 then () | |
107 else docc:ft-search($docPath, $ftQuery) | |
108 | |
109 let $indexTerms := | |
110 if($indexTermsStartStr = "") | |
111 then () | |
112 else docc:indexTerms($docRoot, $indexTermsStartStr, 100) | |
113 | |
114 let $currentTimeEnd := util:system-time() | |
115 let $neededTime := time-util:duration-as-ms($currentTimeEnd - $currentTimeBegin) | |
116 | |
117 let $xmlResult := | |
118 if ($errorCode = 0) | |
119 then | |
120 <result> | |
121 <mode>{$mode}</mode> | |
122 <document-description> | |
123 <document-name>{$document}</document-name> | |
124 {$archimedesInfo} | |
125 <count-pages>{$countPages}</count-pages> | |
126 <performance>{$neededTime}</performance> | |
127 </document-description> | |
128 <page> | |
129 <number>{$pn}</number> | |
130 <image>http://nausikaa2.rz-berlin.mpg.de/digitallibrary/digilib.jsp?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image> | |
131 <image-echo>http://echo.mpiwg-berlin.mpg.de/zogilib?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image-echo> | |
132 <image-scaler>http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image-scaler> | |
133 <xml-url>?document={$document}&pn={$pn}&mode=xml</xml-url> | |
134 <firstFigurePosition>{$positionOfFirstFigureAfterPB1}</firstFigurePosition> | |
135 <content>{$returnPageFragment}</content> | |
136 </page> | |
137 {$ftHits} | |
138 {$indexTerms} | |
139 </result> | |
140 else if ($errorCode = 1) | |
141 then <error>No result: Page {$pn} not found</error> | |
142 else <error>undefined error: {$errorCode}</error> | |
143 | |
144 let $declare := | |
145 if ($mode = "text" or $mode = "image" or $mode = "xml") | |
146 then util:declare-option("exist:serialize", "method=html media-type=text/html omit-xml-declaration=no indent=yes encoding=UTF-8") | |
147 else util:declare-option("exist:serialize", "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=UTF-8") | |
148 | |
149 let $result := transform:transform($xmlResult, doc("/db/xsl/archimedes-page-fragment.xsl"), ()) | |
150 | |
151 return $result |