3 # $Id: search.egw,v 1.7 1995/11/02 16:35:36 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] == ""} {
235 set setNo [lindex $sessionParms 0]
238 if {![info exists hist($nextSetNo,host)]} {
239 set hist($nextSetNo,host) $oldHost
242 html "using host " $hist($setNo,host) " <br\n"
245 set hist($setNo,query) [build-query]
248 set hist($setNo,database) $databases
250 set hist($setNo,database) $b
252 set hist($setNo,maxPresent) [wform hits]
253 if {$hist($setNo,maxPresent) == ""} {
254 set hist($setNo,maxPresent) 30
257 set host $hist($setNo,host)
258 set databases [lindex $targets($host) 1]
260 htmlr {<head><title> WWW/Z39.50 Gateway Search } $host { </title>}
261 htmlr {</head><body>}
262 html "<h2> Search result </h2>\n"
266 set startPos [lindex $sessionParms 1]
267 set endPos [lindex $sessionParms 2]
268 if {$startPos == ""} {
269 research $setNo $oldHost 1
271 set r [z39.$setNo resultCount]
272 html "<h3> $r hits</h3><br>\n"
273 set setOffset [z39.$setNo numberOfRecordsReturned]
274 display-rec 1 $setOffset
277 set setMax [z39.$setNo resultCount]
278 if {$setMax > $hist($setNo,maxPresent)} {
279 set setMax $hist($setNo,maxPresent)
282 research $setNo $oldHost 0
284 set setOffset $startPos
285 set setMax [z39.$setNo resultCount]
286 if {$setMax > $endPos} {
290 set toGet [expr 1 + $setMax - $setOffset]
292 for {set got 0} {$got < $toGet} {incr got} {
293 if {[z39.$setNo type [expr $setOffset + $got]] == ""} {
299 z39.$setNo present $setOffset $toGet
301 if {$sessionWait != "1"} {
304 set got [z39.$setNo numberOfRecordsReturned]
306 display-rec $setOffset [expr $got + $setOffset - 1]
307 set setOffset [expr $got + $setOffset]
308 set toGet [expr 1 + $setMax - $setOffset]
315 html "<strong>Debug information</strong><br>\n"
316 html "sessionId: $sessionId <br>\n"
317 html "sessionParms: $sessionParms <br>\n"
318 foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
319 html $e {: } $env($e) {<br>} \n
321 html "form: " [wform] " <br>\n"
322 html "target: " $host " <br>\n"
323 html "databases: " $hist($setNo,database) " <br>\n"
324 html "selected: " [wform base] " <br>\n"
325 html "query: ->" $hist($setNo,query) "<- <br>"
326 html "setNo: " $setNo " <br>\n"
327 html "nextSetNo: " $nextSetNo " <br>\n"
332 if {$setMax < [z39.$setNo resultCount]} {
333 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
334 html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
335 html + [expr $setMax + $hist($setNo,maxPresent)] {"> Next </a>} "| \n"
337 if {$startPos != ""} {
338 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
339 html / $sessionId {/search.egw/} $setNo
340 if {[expr $startPos - $hist($setNo,maxPresent)] > 1} {
341 html + [expr $startPos - $hist($setNo,maxPresent)]
342 html + [expr $startPos - 1]
344 html {"> Prev </a>} "| \n"
346 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
347 html / $sessionId {/targets.egw"> New target </a>} " | \n"
348 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME)
349 html / $sessionId {/query.egw/} $host + $setNo {"> New query </a>}