-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-new.xql
175 lines (154 loc) · 6.72 KB
/
query-new.xql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
xquery version "3.1";
import module namespace utils="http://exist-db.org/xquery/jgoethe/utils" at "util.xqm";
import module namespace config="http://digital-humanities.de/jgoethe/config" at "config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace kwic="http://exist-db.org/xquery/kwic";
declare namespace ed="http://exist-db.org/xquery/jgoethe";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:media-type "text/html";
declare function ed:load-section($col as xs:string, $id as xs:string) as node()+ {
let $section := collection($col)/configuration/structure//section[@ref=$id]
let $part := util:eval("collection('" || $col || "')//" || $section/@xpath)
return
$part
};
declare function ed:navlink() {
let $parts := request:get-parameter("part", ())
let $sections := request:get-parameter("section", ())
let $col := request:get-parameter("c", ())
let $simple := request:get-parameter("simple", ())
let $display := request:get-parameter("display", "work")
let $offset as xs:integer := request:get-parameter("start", 1)
return
concat("simple=", $simple, "&display=", $display,
string-join(for $p in $parts return concat("&part=", $p), ""),
string-join(for $s in $sections return concat("&section=", $s), ""),
"&c=", $col)
};
declare function ed:display($sections as element()*, $count as xs:integer, $matches as node()*,
$query as xs:string, $mode as xs:string, $col as xs:string) as node()* {
let $width := if ($mode eq "multi") then 300 else 100
let $howmany := if ($count gt 100) then 100 else $count
let $offset as xs:integer := request:get-parameter("start", 1)
let $nodes := subsequence($matches, $offset, $howmany)
for $hit at $pos in $nodes
let $node := $hit,
$id0 := ($node/ancestor::l/@xml:id|$node/ancestor::lg/@xml:id|$node/ancestor::sp/@xml:id|$node/ancestor::p/@xml:id),
$id := (if ($id0) then $id0[1] else $node/ancestor::*/@xml:id[last()])[1],
$link := "javascript:top.displayQueryResult(null,'single','"|| $query ||"','" || $id || "','" || util:node-id($node) || "', " || $pos || ")" (: FIXME Leerstellen :),
$titles := for $a in $hit/ancestor::*
let $h := $a/head
return if ($h and exists($sections//$h)) then utils:process-head($h[1]) else ()
return (
<li class="{if ($pos mod 2 eq 0) then 'hi hierarchy' else 'hierarchy'}">
{string-join($titles, ' | ')}
</li>,
<li>
{if ($pos mod 2 eq 0) then attribute class { 'hi'} else ()}
{kwic:summarize($hit, <config width="{$width}" table="no" link="{$link}"/>)}
</li>
)
};
declare function ed:display-overview($col as xs:string, $sections as element()*, $matches as node()*, $simple as xs:string) as node()* {
<ul>
{
for $sect in $sections
for $div at $pos in utils:get-divs($col, $sect)
let $hits := $div//$matches
let $count := count($hits)
where $count gt 0
return
let $first := $hits[1]
let $id := ($first/ancestor-or-self::*/@xml:id)[last()]
return
<li>
<a class="overview" href="#"
onclick="return top.displayQueryResult(null, 'overview', '{$simple}', '{$id}', '{$div/@xml:id}')">
<b>{utils:process-head($sect/head)}</b> /
{ utils:process-head($div/head)} / { $count }
</a>
</li>
}
</ul>
};
declare function ed:query($col as xs:string, $divs as node()*) as node()* {
let $simple := request:get-parameter("simple", ())
let $display := request:get-parameter("display", "work")
let $offset as xs:integer := request:get-parameter("start", 1)
let $hits := utils:ftquery($divs, $simple)
let $count := count($hits)
let $howmany := if ($count gt 100) then 100 else $count
return
<ul>
{
if ($display eq "work") then
ed:display-overview($col, $divs, $hits, $simple)
else (
<li class="info-top">
{
if ($count gt 100) then
<a class="nav-right" rel="next"
href="query-new.xql?start={$offset + $howmany}&{ed:navlink()}">
Weitere >>
</a>
else
()
}
{
if ($offset gt 1) then
<a class="nav-left" rel="prev"
href="query-new.xql?start={$offset - $howmany}&{ed:navlink()}">
<< Vorherige</a>
else
()
}
<div class="message">{$count} Treffer gefunden. Zeige Treffer {$offset} bis
{$offset + $howmany - 1}.</div>
</li>,
ed:display($divs, $count, $hits, $simple, $display, $col),
<li class="info-bottom">
{
if ($count gt 100) then
<a class="nav-right"
href="query-new.xql?start={$offset + $howmany}&{ed:navlink()}">
Weitere >>
</a>
else
()
}
{
if ($offset gt 1) then
<a class="nav-left"
href="query-new.xql?start={$offset - $howmany}&{ed:navlink()}">
<< Vorherige
</a>
else
()
}
<div class="message">{$count} Treffer gefunden. Zeige Treffer {$offset} bis
{$offset + $howmany - 1}.</div>
</li>
)
}
</ul>
};
let $parts := request:get-parameter("part", ())
let $sections := request:get-parameter("section", ())
let $col := $config:col (: :request:get-parameter("c", ()) FIXME :)
let $divs :=
if (exists($sections)) then
for $s in $sections return (collection($col)/id($s), console:log('Section: ' || $s || ', col=' || $col))
else if (exists($parts)) then
for $p in $parts return ed:load-section($col, $p)
else
()
return
<html>
<head>
<title>Search Results</title>
<link href="styles/query.css" type="text/css" rel="stylesheet"/>
</head>
<body onload="top.searchCompleted()">
{ed:query($col, $divs)}
</body>
</html>