10 |
use Config::IniFiles; |
use Config::IniFiles; |
11 |
use Text::Unaccent; |
use Text::Unaccent; |
12 |
use Data::Pageset; |
use Data::Pageset; |
13 |
|
use POSIX qw(locale_h); |
14 |
|
|
15 |
use lib '..'; |
use lib '..'; |
16 |
use index_DBI_filter; |
use index_DBI_filter; |
33 |
my $BASE_PATH =$cfg_global->val('webpac', 'base_path'); |
my $BASE_PATH =$cfg_global->val('webpac', 'base_path'); |
34 |
# for pager |
# for pager |
35 |
my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10; |
my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10; |
36 |
|
my $locale = $cfg_global->val('locale') || 'hr_HR'; |
37 |
|
|
38 |
Text::Iconv->raise_error(0); # Conversion errors raise exceptions |
Text::Iconv->raise_error(0); # Conversion errors raise exceptions |
39 |
|
|
40 |
my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); |
my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); |
41 |
|
|
42 |
|
setlocale(LC_CTYPE, $locale); |
43 |
|
setlocale(LC_COLLATE, $locale); |
44 |
|
|
45 |
if ($UNAC_FILTER) { |
if ($UNAC_FILTER) { |
46 |
require $UNAC_FILTER; |
require $UNAC_FILTER; |
47 |
} else { |
} else { |
191 |
foreach my $v (@persist_vars) { |
foreach my $v (@persist_vars) { |
192 |
foreach my $val ($q->param($v)) { |
foreach my $val ($q->param($v)) { |
193 |
next if (! $val || $val eq ''); |
next if (! $val || $val eq ''); |
194 |
|
$val =~ s/"/"/g; |
195 |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
196 |
$hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm"); |
$hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm"); |
197 |
} |
} |
233 |
|
|
234 |
my $q = $self->query(); |
my $q = $self->query(); |
235 |
|
|
236 |
|
# submit was reset? |
237 |
|
if ($q->param('reset')) { |
238 |
|
$q->delete_all; |
239 |
|
return $self->show_search_form(); |
240 |
|
} |
241 |
|
|
242 |
# load template for this page |
# load template for this page |
243 |
|
|
244 |
my @s_arr; # all queries are located here |
my @s_arr; # all queries are located here |
279 |
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); |
280 |
|
|
281 |
foreach my $v ($q->url_param("v$i")) { |
foreach my $v ($q->url_param("v$i")) { |
282 |
|
# escape quotes so that phrase search work |
283 |
|
$v =~ s/"/%22/g; |
284 |
push @url_params,"v$i=$v"; |
push @url_params,"v$i=$v"; |
285 |
push @url_params_persist,"v$i=$v" if ($persist); |
push @url_params_persist,"v$i=$v" if ($persist); |
286 |
} |
} |
337 |
} |
} |
338 |
} |
} |
339 |
$s =~ s/\*+/*/g; |
$s =~ s/\*+/*/g; |
340 |
|
$s =~ s/[()]//g; # () are used in query language |
341 |
$s = $pre.$s.$post if ($q->param("e$i")); |
$s = $pre.$s.$post if ($q->param("e$i")); |
342 |
push @swish_q,$s; |
push @swish_q,$s; |
343 |
} |
} |
348 |
|
|
349 |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); |
350 |
|
|
|
$tmpl->param('url_params',"?".join("&",@url_params)); |
|
|
|
|
351 |
sub esc_html { |
sub esc_html { |
352 |
my $html = shift; |
my $html = shift; |
353 |
$html =~ s/</</g; |
$html =~ s/</</g; |
366 |
$sort = $sortby; |
$sort = $sortby; |
367 |
push @persist_vars, "sortby"; |
push @persist_vars, "sortby"; |
368 |
} |
} |
369 |
$tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
# used to filter entries in index and swish |
370 |
|
my $filter = $q->param("filter"); |
371 |
|
|
372 |
# construct swish query |
# construct swish query |
373 |
my $sw_q = join(" and ",@s_arr); |
my $sw_q = join(" and ",@s_arr); |
374 |
if (@path_arr && $q->param('show_full')) { |
if (@path_arr && $q->param('show_full')) { |
375 |
$sw_q .= "and (swishdocpath=\""; |
$sw_q .= " and (swishdocpath=\""; |
376 |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
377 |
$sw_q .= "\")"; |
$sw_q .= "\")"; |
378 |
$tmpl->param('full',1); # show full records |
$tmpl->param('full',1); # show full records |
379 |
|
# } elsif (@path_arr && $#path_arr == 0) { |
380 |
|
# # I will assume that it's a filter since there isn't show_full |
381 |
|
# $filter = shift @path_arr; |
382 |
} elsif ($q->param('show_full')) { |
} elsif ($q->param('show_full')) { |
383 |
# just show full path, no path defined |
# just show full path, no path defined |
384 |
$tmpl->param('full',1); |
$tmpl->param('full',1); |
386 |
$tmpl->param('full',0); |
$tmpl->param('full',0); |
387 |
} |
} |
388 |
|
|
389 |
|
if ($filter) { |
390 |
|
$sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr); |
391 |
|
push @persist_vars, "filter"; |
392 |
|
push @url_params, "filter=$filter"; |
393 |
|
push @url_params_persist, "filter=$filter"; |
394 |
|
} |
395 |
|
|
396 |
my $swish_msg = ' '; |
my $swish_msg = ' '; |
397 |
|
|
398 |
# create new swish instance |
# create new swish instance |
417 |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
418 |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
419 |
|
|
420 |
|
# URL parametars for search results |
421 |
|
$tmpl->param('url_params',"?".join("&",@url_params)); |
422 |
|
$tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
# |
# |
427 |
# build pager |
# build pager |
428 |
# |
# |
506 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
507 |
$tmpl->param('limit',$limit); |
$tmpl->param('limit',$limit); |
508 |
$tmpl->param('total',$total); |
$tmpl->param('total',$total); |
509 |
|
$tmpl->param('filter',$filter); |
510 |
|
|
511 |
# FIXME I should set offset and leave out limit from fetch!! |
# FIXME I should set offset and leave out limit from fetch!! |
512 |
# if (! $q->param("PAGER_offset") { |
# if (! $q->param("PAGER_offset") { |