182 |
my $tmpl = shift @_; |
my $tmpl = shift @_; |
183 |
my @persist_vars = @_; |
my @persist_vars = @_; |
184 |
my $hidden_vars = ''; |
my $hidden_vars = ''; |
185 |
|
my $hidden_search = ''; |
186 |
foreach my $v (@persist_vars) { |
foreach my $v (@persist_vars) { |
187 |
foreach my $val ($q->param($v)) { |
foreach my $val ($q->param($v)) { |
188 |
next if (! $val || $val eq ''); |
next if (! $val || $val eq ''); |
189 |
|
$val =~ s/"/"/g; |
190 |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
191 |
|
$hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm"); |
192 |
} |
} |
193 |
} |
} |
194 |
|
|
195 |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
196 |
|
$tmpl->param('SEARCH_HIDDEN', $hidden_search); |
197 |
$tmpl->param('PAGER_JAVASCRIPT', qq# |
$tmpl->param('PAGER_JAVASCRIPT', qq# |
198 |
<SCRIPT LANGUAGE="Javascript"> |
<SCRIPT LANGUAGE="Javascript"> |
199 |
<!-- Begin |
<!-- Begin |
228 |
|
|
229 |
my $q = $self->query(); |
my $q = $self->query(); |
230 |
|
|
231 |
|
# submit was reset? |
232 |
|
if ($q->param('reset')) { |
233 |
|
$q->delete_all; |
234 |
|
return $self->show_search_form(); |
235 |
|
} |
236 |
|
|
237 |
# load template for this page |
# load template for this page |
238 |
|
|
239 |
my @s_arr; # all queries are located here |
my @s_arr; # all queries are located here |
274 |
push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); |
push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); |
275 |
|
|
276 |
foreach my $v ($q->url_param("v$i")) { |
foreach my $v ($q->url_param("v$i")) { |
277 |
|
# escape quotes so that phrase search work |
278 |
|
$v =~ s/"/%22/g; |
279 |
push @url_params,"v$i=$v"; |
push @url_params,"v$i=$v"; |
280 |
push @url_params_persist,"v$i=$v" if ($persist); |
push @url_params_persist,"v$i=$v" if ($persist); |
281 |
} |
} |
340 |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
341 |
} |
} |
342 |
|
|
343 |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); |
344 |
|
|
345 |
$tmpl->param('url_params',"?".join("&",@url_params)); |
$tmpl->param('url_params',"?".join("&",@url_params)); |
346 |
|
|
357 |
push @persist_vars, "sort"; |
push @persist_vars, "sort"; |
358 |
} |
} |
359 |
|
|
360 |
|
my $sortby = $q->param("sortby"); |
361 |
|
if ($sortby) { |
362 |
|
$sort = $sortby; |
363 |
|
push @persist_vars, "sortby"; |
364 |
|
} |
365 |
|
$tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
366 |
|
|
367 |
# construct swish query |
# construct swish query |
368 |
my $sw_q = join(" and ",@s_arr); |
my $sw_q = join(" and ",@s_arr); |
369 |
if (@path_arr && $q->param('show_full')) { |
if (@path_arr && $q->param('show_full')) { |
378 |
$tmpl->param('full',0); |
$tmpl->param('full',0); |
379 |
} |
} |
380 |
|
|
381 |
|
my $swish_msg = ' '; |
382 |
|
|
383 |
# create new swish instance |
# create new swish instance |
384 |
my $swish = SWISH::API->new($INDEX); |
my $swish = SWISH::API->new($INDEX); |
385 |
die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
386 |
|
|
387 |
# execute query and get number of results from SWISH-E |
# execute query and get number of results from SWISH-E |
388 |
my $search = $swish->New_Search_Object; |
my $search = $swish->New_Search_Object; |
390 |
$search->SetSort($sort); |
$search->SetSort($sort); |
391 |
|
|
392 |
my $results = $search->Execute($sw_q); |
my $results = $search->Execute($sw_q); |
393 |
die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
394 |
|
|
395 |
my $hits = $results->Hits; |
my $hits = $results->Hits; |
396 |
|
|
397 |
$tmpl->param('hits',$hits); |
$tmpl->param('hits',$hits); |
398 |
$tmpl->param('search',$sw_q); |
my $search_msg = $sw_q; |
399 |
|
$search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg); |
400 |
|
$tmpl->param('search', $search_msg); |
401 |
|
|
402 |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
403 |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
481 |
return $html; |
return $html; |
482 |
} |
} |
483 |
|
|
484 |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0); |
485 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
486 |
$tmpl->param('limit',$limit); |
$tmpl->param('limit',$limit); |
487 |
$tmpl->param('total',$total); |
$tmpl->param('total',$total); |
488 |
|
$tmpl->param('filter',$filter); |
489 |
|
|
490 |
# FIXME I should set offset and leave out limit from fetch!! |
# FIXME I should set offset and leave out limit from fetch!! |
491 |
# if (! $q->param("PAGER_offset") { |
# if (! $q->param("PAGER_offset") { |