3 # $Id: search.egw,v 1.6 1995/11/01 16:15:45 adam Exp $
5 proc search-response {sno} {
8 set status [z39.$sno responseStatus]
9 if {[lindex $status 0] == "NSD"} {
10 z39.$sno nextResultSetPosition 0
11 set code [lindex $status 1]
12 set msg [lindex $status 2]
13 set addinfo [lindex $status 3]
14 htmlr {<strong>Error} $code {: } $msg {: } $addinfo { </strong><br>}
26 proc fail-response {} {
31 proc display-brief {zset no} {
36 set type [$zset type $no]
38 set err [lindex [$zset diag $no] 1]
39 set add [lindex [$zset diag $no] 2]
43 htmlr "${no} Error ${err}${add} <br>"
50 set rtype [$zset recordType $no]
51 if {$rtype == "SUTRS"} {
52 html [join [$zset getSutrs $no]]
57 set title [lindex [$zset getMarc $no field 245 * a] 0]
58 set year [lindex [$zset getMarc $no field 260 * c] 0]
60 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME) /
61 html $sessionId {/showfull.egw/} $setNo + $no {"> } $title {</a>}
62 html " <i> ${year} </i>"
67 proc display-full {zset no} {
68 set type [$zset type $no]
70 set err [lindex [$zset diag $no] 1]
71 set add [lindex [$zset diag $no] 2]
75 htmlr "<hr> ${no} <br>"
76 htmlr "Error ${err}${add} <br>"
82 htmlr "<hr> ${no} <br>"
83 set rtype [$zset recordType $no]
84 if {$rtype == "SUTRS"} {
85 htmlr [join [$zset getSutrs $no]]
88 if {[catch {set r [$zset getMarc $no line * * *]}]} {
89 htmlr "Unknown record type: $rtype"
93 set tag [lindex $line 0]
94 set indicator [lindex $line 1]
95 set fields [lindex $line 2]
96 set l [string length $indicator]
99 for {set i 0} {$i < $l} {incr i} {
100 if {[string index $tag $i] == " "} {
103 html [string index $tag $i]
107 foreach field $fields {
108 set id [lindex $field 0]
109 set data [lindex $field 1]
111 html " <b>\$$id</b> "
119 proc display-rec {from to} {
122 while {$from <= $to} {
123 display-brief z39.$setNo $from
128 proc build-query {} {
134 for {set i 1} {$i < 4} {incr i} {
135 set term [wform entry$i]
137 set field [wform menu$i]
138 foreach x [lindex $targets($t) 2] {
139 if {[lindex $x 0] == $field} {
140 set attr [lindex $x 1]
145 { set q "@and $q ${attr} ${term}" }
147 { set q "@or $q ${attr} ${term}" }
149 { set q "@not $q ${attr} ${term}" }
151 { set q "${attr} ${term}" }
153 set op [wform logic$i]
159 proc research {setNo oldHost piggy} {
163 set host $hist($setNo,host)
164 if {[catch {z39 failback fail-response}]} {
167 if {[catch {set oldHost [z39 connect]}]} {
170 z39 callback ok-response
171 z39 failback fail-response
172 if {$oldHost != $host} {
173 catch {z39 disconnect}
175 html "Connecting to target " $host " <br>\n"
177 if {[catch {z39 connect $host}]} {
178 htmlr "Cannot connect to target ${host} <br>"
179 htmlr "</body></html>"
181 } elseif {$sessionWait == 0} {
183 if {$sessionWait != 1} {
184 htmlr "Cannot connect to target ${host} <br>"
185 htmlr "</body></html>"
192 if {$sessionWait != "1"} {
193 htmlr "Cannot initialize with target ${host} <br>"
194 htmlr "</body></html>"
198 if {![catch {z39.$setNo smallSetUpperBound 0}]} {
201 ir-set z39.$setNo z39
202 eval z39.$setNo databaseNames $hist($setNo,database)
204 z39.$setNo preferredRecordSyntax USMARC
206 z39 callback search-response $setNo
208 z39.$setNo largeSetLowerBound 999999
209 z39.$setNo smallSetUpperBound 0
210 z39.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
212 z39.$setNo largeSetLowerBound 2
213 z39.$setNo smallSetUpperBound 0
214 z39.$setNo mediumSetPresentNumber 0
217 z39.$setNo search $hist($setNo,query)
220 if {$sessionWait != 1} {
221 htmlr {</body></html>}
231 set oldHost $hist($setNo,host)
233 if {[wform menu1] == ""} {
234 set setNo [lindex $sessionParms 0]
236 if {![info exists hist($nextSetNo,host)]} {
237 set hist($nextSetNo,host) $oldHost
242 set hist($setNo,query) [build-query]
245 set hist($setNo,database) $databases
247 set hist($setNo,database) $b
249 set hist($setNo,maxPresent) [wform hits]
250 if {$hist($setNo,maxPresent) == ""} {
251 set hist($setNo,maxPresent) 30
254 set host $hist($setNo,host)
255 set databases [lindex $targets($host) 1]
257 htmlr {<head><title> WWW/Z39.50 Gateway Search } $host { </title>}
258 htmlr {</head><body>}
259 html "<h2> Search result </h2>\n"
263 set startPos [lindex $sessionParms 1]
264 set endPos [lindex $sessionParms 2]
265 if {$startPos == ""} {
266 research $setNo $oldHost 1
268 set r [z39.$setNo resultCount]
269 html "<h3> $r hits</h3><br>\n"
270 set setOffset [z39.$setNo numberOfRecordsReturned]
271 display-rec 1 $setOffset
274 set setMax [z39.$setNo resultCount]
275 if {$setMax > $hist($setNo,maxPresent)} {
276 set setMax $hist($setNo,maxPresent)
279 research $setNo $oldHost 0
281 set setOffset $startPos
282 set setMax [z39.$setNo resultCount]
283 if {$setMax > $endPos} {
287 set toGet [expr 1 + $setMax - $setOffset]
289 for {set got 0} {$got < $toGet} {incr got} {
290 if {[z39.$setNo type [expr $setOffset + $got]] == ""} {
296 z39.$setNo present $setOffset $toGet
298 if {$sessionWait != "1"} {
301 set got [z39.$setNo numberOfRecordsReturned]
303 display-rec $setOffset [expr $got + $setOffset - 1]
304 set setOffset [expr $got + $setOffset]
305 set toGet [expr 1 + $setMax - $setOffset]
312 html "<strong>Debug information</strong><br>\n"
313 html "sessionId: $sessionId <br>\n"
314 html "sessionParms: $sessionParms <br>\n"
315 foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
316 html $e {: } $env($e) {<br>} \n
318 html "form: " [wform] " <br>\n"
319 html "target: " $host " <br>\n"
320 html "databases: " $hist($setNo,database) " <br>\n"
321 html "selected: " [wform base] " <br>\n"
322 html "query: ->" $hist($setNo,query) "<- <br>"
323 html "setNo: " $setNo " <br>\n"
324 html "nextSetNo: " $nextSetNo " <br>\n"
329 if {$setMax < [z39.$setNo resultCount]} {
330 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
331 html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
332 html + [expr $setMax + $hist($setNo,maxPresent)] {"> Next </a>} "| \n"
334 if {$startPos != ""} {
335 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
336 html / $sessionId {/search.egw/} $setNo
337 if {[expr $startPos - $hist($setNo,maxPresent)] > 1} {
338 html + [expr $startPos - $hist($setNo,maxPresent)]
339 html + [expr $startPos - 1]
341 html {"> Prev </a>} "| \n"
343 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
344 html / $sessionId {/targets.egw"> New target </a>} " | \n"
345 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
346 html / $sessionId {/query.egw/} $host {"> New query </a>}