9
<title>Search Swish-e Documenation</title>
10
<frameset rows="20%,*" frameborder="0" border="0" framespacing="0">
11
<frame src="swish.cgi">
18
#=====================================================================
19
# These routines format the HTML output.
20
# $Id: TemplateFrame.pm,v 1.1 2003/10/03 23:50:06 whmoseley Exp $
21
#=====================================================================
22
package SWISH::TemplateFrame;
28
my ( $class, $template_params, $results ) = @_;
31
my $q = $results->CGI;
35
my $output = $q->header . page_header( $results );
38
unless ( $results->results || $results->errstr ) {
39
$output .= show_form( $results );
43
if ( $results->results ) {
44
$output .= results_header( $results );
45
$output .= show_result( $results, $_ ) for @{ $results->results };
47
if ( $results->{links} ) {
48
$output .= "<table>$results->{links}</table>";
51
$output .= '<font size="+2" color="red">'
52
. $results->errstr || 'unknown error'
57
$output .= '</body></html>';
63
#=====================================================================
64
# This generates the header
68
my $title = $results->config('title') || 'Search our site with Swish-e';
71
my $html_title = $results->results
72
? ( $results->navigation('hits')
74
. CGI::escapeHTML( $results->{query_simple} )
78
: ( $results->errstr || $title );
81
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
92
#=====================================================================
93
# This generates the form
101
my $q = $results->{q};
104
my $query = $q->param('query') || '';
106
$query = CGI::escapeHTML( $query ); # May contain quotes
109
# Here's some form components
111
my $meta_select_list = get_meta_name_limits( $results );
112
my $sorts = get_sort_select_list( $results );
113
my $select_index = get_index_select_list( $results );
114
my $limit_select = get_limit_select( $results );
116
my $date_ranges_select = $results->get_date_ranges;
118
my $form = $q->script_name;
120
my $advanced_link = qq[<small><a href="$form">advanced form</a></small>];
122
my $advanced_form = $q->param('brief')
132
my $extra = $results->config('extra_fields');
133
my $hidden = !$extra ? ''
134
: join "\n", map { $q->hidden($_) } @$extra;
137
my $title = $results->config('title') || 'Search our site with Swish-e';
143
<form method="get" action="$form" enctype="application/x-www-form-urlencoded" class="form" target="bottom">
144
<input maxlength="200" value="$query" size="32" type="text" name="query"/>
146
<input value="Search!" type="submit" name="submit"/><br>
154
#=====================================================================
155
# This routine creates the results header display
164
my $config = $results->{config};
165
my $q = $results->{q};
169
my $swr = $results->header('removed stopwords');
173
if ( $swr && ref $swr eq 'ARRAY' ) {
174
$stopwords = @$swr > 1
175
? join( ', ', map { "<b>$_</b>" } @$swr ) . ' are very common words and were not included in your search'
176
: join( ', ', map { "<b>$_</b>" } @$swr ) . ' is a very common word and was not included in your search';
184
if ( $results->{DateRanges_time_low} && $results->{DateRanges_time_high} ) {
185
my $low = scalar localtime $results->{DateRanges_time_low};
186
my $high = scalar localtime $results->{DateRanges_time_high};
190
<font size="-2" face="Geneva, Arial, Helvetica, San-Serif">
191
Results limited to dates $low to $high
198
my $query_href = $results->{query_href};
199
my $query_simple = CGI::escapeHTML( $results->{query_simple} );
200
my $pages = $results->navigation('pages');
202
my $prev = $results->navigation('prev');
203
my $prev_count = $results->navigation('prev_count');
204
my $next = $results->navigation('next');
205
my $next_count = $results->navigation('next_count');
207
my $hits = $results->navigation('hits');
208
my $from = $results->navigation('from');
209
my $to = $results->navigation('to');
211
my $run_time = $results->navigation('run_time');
212
my $search_time = $results->navigation('search_time');
220
$links .= '<font size="-1" face="Geneva, Arial, Helvetica, San-Serif"> Page:</font>' . $pages
223
$links .= qq[ <a href="$query_href&start=$prev">Previous $prev_count</a>]
226
$links .= qq[ <a href="$query_href&start=$next">Next $next_count</a>]
230
# Save for the bottom of the screen.
231
$results->{LINKS} = $links;
233
$links = qq[<tr><td colspan="2" bgcolor="#EEEEEE">$links</td></tr>] if $links;
235
$query_simple = $query_simple
236
? " Results for <b>$query_simple</b>"
240
$results->{links} = $links if $links;
244
<table cellpadding="0" cellspacing="0" border="0" width="100%">
246
<td height=20 bgcolor="#FF9999">
247
<font size="-1" face="Geneva, Arial, Helvetica, San-Serif">
249
$from to $to of $hits results.
252
<td align=right bgcolor="#FF9999">
253
<font size="-2" face="Geneva, Arial, Helvetica, San-Serif">
254
Run time: $run_time |
255
Search time: $search_time
270
#=====================================================================
271
# This routine formats a single result
275
my ($results, $this_result ) = @_;
277
my $conf = $results->{conf};
279
my $DocTitle = $results->config('title_property') || 'swishtitle';
282
my $title = $this_result->{$DocTitle} || $this_result->{swishdocpath} || '?';
284
my $name_labels = $results->config('name_labels');
288
# The the properties to display
292
my $display_props = $results->config('display_props');
293
if ( $display_props ) {
297
'<br><table cellpadding="0" cellspacing="0">',
300
. ( $name_labels->{$_} || $_ )
301
. ':</small></td><td><small> '
303
. ( defined $this_result->{$_} ? $this_result->{$_} : '' )
305
. '</small></td></tr>'
312
my $description_prop = $results->config('description_prop');
314
my $description = '';
315
if ( $description_prop ) {
316
$description = $this_result->{ $description_prop } || '';
322
<dt>$this_result->{swishreccount} <a href="$this_result->{swishdocpath_href}">$title</a> <small>-- rank: <b>$this_result->{swishrank}</b></small></dt>
334
#==================================================================
335
# Form setup for sorts and metas
337
# This could be methods of $results object
338
# (and then available for Template-Toolkit)
339
# But that's too much HTML in the object, perhaps.
342
#==================================================================
344
sub get_meta_name_limits {
345
my ( $results ) = @_;
347
my $metanames = $results->config('metanames');
348
return '' unless $metanames;
351
my $name_labels = $results->config('name_labels');
352
my $q = $results->CGI;
359
-values => $metanames,
360
-default=>$metanames->[0],
361
-labels =>$name_labels
366
sub get_sort_select_list {
367
my ( $results ) = @_;
369
my $sort_metas = $results->config('sorts');
370
return '' unless $sort_metas;
373
my $name_labels = $results->config('name_labels');
374
my $q = $results->CGI;
382
-values => $sort_metas,
383
-default=>$sort_metas->[0],
384
-labels =>$name_labels
388
-label => 'Reverse Sort'
394
sub get_index_select_list {
395
my ( $results ) = @_;
396
my $q = $results->CGI;
399
my $indexes = $results->config('swish_index');
400
return '' unless ref $indexes eq 'ARRAY';
402
my $select_config = $results->config('select_indexes');
403
return '' unless $select_config && ref $select_config eq 'HASH';
406
# Should return a warning, as this might be a likely mistake
407
# This jumps through hoops so that real index file name is not exposed
409
return '' unless exists $select_config->{labels}
410
&& ref $select_config->{labels} eq 'ARRAY'
411
&& @$indexes == @{$select_config->{labels}};
414
my @labels = @{$select_config->{labels}};
417
for ( 0..$#labels ) {
418
$map{$_} = $labels[$_];
421
my $method = $select_config->{method} || 'checkbox_group';
422
my @cols = $select_config->{columns} ? ('-columns', $select_config->{columns}) : ();
426
( $select_config->{description} || 'Select: '),
429
-values => [0..$#labels],
436
sub get_limit_select {
437
my ( $results ) = @_;
438
my $q = $results->CGI;
441
my $limit = $results->config('select_by_meta');
442
return '' unless ref $limit eq 'HASH';
444
my $method = $limit->{method} || 'checkbox_group';
448
-values => $limit->{values},
449
-labels => $limit->{labels} || {},
452
push @options, ( -columns=> $limit->{columns} ) if $limit->{columns};
457
( $limit->{description} || 'Select: '),
458
$q->$method( @options );