Example 10-4. Sorting
We'll present a ZAP template that retrieves at most 100 USMARC records from the target and show 10 records at a time. We use title (field 245, subfield a) as sorting critieria.
The template could be invoked the search form presented in Example 1-1.
%%override servertotal=s number=100 show_number=10 %%def syntax=sutrs %%begin <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title>ZAP! Search Result</title> </head> <body> %%end </body> </html> %%query-empty <h1>ZAP! Search Result</h1> You specified an empty query. Go back and try again!<br> %%query-ok <h1>ZAP! Search Result</h1> Your query was $query.<br> %%server-error connection <hr><h2>Couldn't connect to $target.</h2> %%server-error protocol <hr><h2>$target: Protocol error</h2> %%server-error init <hr><h2>$target: Connection rejected</h2> %%server-error 114 <hr><dt><h2>$target: </h2><dd>You specified a field that this system does not recognise.<br><dt> %%server-error <hr><dt><h2>$target: Search error</h2><dd>$errorstring${addinfo?\: $addinfo} ($errorcode)<dt> %%server-hits 0 <hr><h2>$target: No hits</h2> %%server-hits 1 <hr><h2>$target: one hit</h2> %%server-hits <hr><h2>$target: $hits hits</h2> %%sort-format usmarc 245 "" 245/* "" 245/*/a "%{ set sort $data %}" %%format usmarc 245 "" 245/* "" 245/*/a "$data<br>" %%record sutrs <p> #$no: <pre> $record </pre> </p> %%records begin <dl> %%records end </dl> %{ if {![info exists show_offset]} { set show_offset 0 } html "show_offset = $show_offset<br/>" if {$show_offset >= $show_number} { html "settting prev offset<br/>" setz prev_show_offset [expr $show_offset - $show_number] } else { setz prev_show_offset {} } if {$show_offset < [expr $hits - $show_number]} { setz next_show_offset [expr $show_offset + $show_number] html "setting next_offset<br/>"; } else { setz next_show_offset {} } %} ${prev_show_offset?<a href="?show_offset=${prev_show_offset}&${term*=}&${target*=}&${field*=}&${element=}&${syntax=}">Previous Page</a>} ${next_show_offset?<a href="?show_offset=${next_show_offset}&${term*=}&${target*=}&${field*=}&${element=}&${syntax=}">Next Page</a>} |
The TCL code in the %%records end section calculates the offsets for previous page and next page. If prev_show_offset is a non-empty string, the previous page button is displayed. And the same mechanism is used for next_show_offset.