+proc score-sort {l r} {
+ return [expr [lindex $r 0] - [lindex $l 0]]
+}
+
+proc display-result-set-m-score {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+
+ set not $hist($setNo,0,host)
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] != "DBOSD"} continue
+ set nor $hist($setNo,$i,offset)
+ for {set j 1} {$j <= $nor} {incr j} {
+ if {![string compare [z39$i.$setNo recordType $j] WAIS]} {
+ set score [z39$i.$setNo getWAIS $j score]
+ } elseif {![string compare [z39$i.$setNo recordType $j] USmarc]} {
+ set score [z39$i.$setNo getMarc $j field 999 * r]
+ if {[scan $score %d score] != 1} {
+ set score 10
+ }
+ } else {
+ set score 10
+ }
+ if {$score > 0} {
+ lappend scoreArray [list $score $i $j]
+ }
+ }
+ }
+ if {![info exists scoreArray]} {
+ html "<br><h3>Search produced no result</h3><br>\n"
+ } else {
+ html "<ul>\n"
+ set scoreSorted [lsort -command score-sort $scoreArray]
+ foreach r $scoreSorted {
+ set i [lindex $r 1]
+ set j [lindex $r 2]
+ display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
+ }
+ html "<br></ul>\n"
+ }
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ z39$i.$setNo nextResultSetPosition 0
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
+ html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
+ }
+ }
+ html "\n<br>"
+}
+
+proc display-result-set-m-server {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+ global env
+ global sessionId
+
+ set not $hist($setNo,0,host)
+ html "<dl>\n"
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
+ z39$i.$setNo nextResultSetPosition 0
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
+ } else {
+ html {<dt><a href="http:} $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + $i + 1
+ html + $hist($setNo,maxPresent) {">}
+ html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
+ set r [z39$i.$setNo resultCount]
+ html "$r hits</h3>\n<dd>\n"
+
+ if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
+ set nor $hist($setNo,maxPresent)
+ } else {
+ set nor $hist($setNo,$i,offset)
+ }
+ display-rec 1 $nor display-$hist($setNo,format) $setNo $i
+ }
+ html "\n"
+ }
+ html "</dl>\n"
+}
+
+proc display-result-set-m {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+
+ egw_log debug "sort=$hist($setNo,sort)"
+ switch $hist($setNo,sort) {
+ score {
+ display-result-set-m-score $setNo
+ }
+ default {
+ display-result-set-m-server $setNo
+ }
+ }
+}
+