--- branches/humanistika/WebPac.pm 2005/03/01 19:32:23 687 +++ branches/humanistika/WebPac.pm 2005/09/11 18:45:50 710 @@ -10,6 +10,7 @@ use Config::IniFiles; use Text::Unaccent; use Data::Pageset; +use POSIX qw(locale_h); use lib '..'; use index_DBI_filter; @@ -32,11 +33,15 @@ my $BASE_PATH =$cfg_global->val('webpac', 'base_path'); # for pager my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10; +my $locale = $cfg_global->val('locale') || 'hr_HR'; Text::Iconv->raise_error(0); # Conversion errors raise exceptions my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); +setlocale(LC_CTYPE, $locale); +setlocale(LC_COLLATE, $locale); + if ($UNAC_FILTER) { require $UNAC_FILTER; } else { @@ -186,7 +191,7 @@ foreach my $v (@persist_vars) { foreach my $val ($q->param($v)) { next if (! $val || $val eq ''); - $val =~ s/"/"e;/g; + $val =~ s/"/"/g; $hidden_vars .= ''."\n"; $hidden_search .= ''."\n" if ($v ne "rm"); } @@ -242,14 +247,18 @@ my $full = $q->param('full'); my @persist_vars = ( 'rm', 'persist_search' ); - my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) ); + my $url_params = { + 'rm' => 'results', + 'show_full' => 1, + 'last_PAGER_offset' => ($q->param('PAGER_offset') || 0), + }; my @persist_search_vars; - my @url_params_persist; + my $url_params_persist = {}; if ($q->param("persist_search")) { @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search")); - push @url_params_persist, "persist_search=".$q->url_param("persist_search"); - push @url_params,"persist_search=".$q->url_param("persist_search"); + $url_params_persist->{'persist_search'} = $q->url_param("persist_search"); + $url_params->{'persist_search'} = $q->url_param("persist_search"); } # support parametars "f" and "v" for start @@ -270,19 +279,19 @@ # create url parametars (and persistent ones) - push @url_params,"f$i=".$q->url_param("f$i"); - push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); + $url_params->{"f$i"} = $q->url_param("f$i"); + $url_params_persist->{"f$i"} = $q->url_param("f$i") if ($persist); foreach my $v ($q->url_param("v$i")) { # escape quotes so that phrase search work $v =~ s/"/%22/g; - push @url_params,"v$i=$v"; - push @url_params_persist,"v$i=$v" if ($persist); + $url_params->{"v$i"} = $v; + $url_params_persist->{"v$i"} = $v if ($persist); } if ($q->param("e$i")) { - push @url_params,"e$i=".$q->url_param("e$i"); -# push @url_params_persist,"e$i=".$q->url_param("e$i"); + $url_params->{"e$i"} = $q->url_param("e$i"); +# $url_params_persist->{"e$i"} = $q->url_param("e$i"); } my $wc="*"; # swish wildcard @@ -332,6 +341,7 @@ } } $s =~ s/\*+/*/g; + $s =~ s/[()]//g; # () are used in query language $s = $pre.$s.$post if ($q->param("e$i")); push @swish_q,$s; } @@ -342,8 +352,6 @@ my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); - $tmpl->param('url_params',"?".join("&",@url_params)); - sub esc_html { my $html = shift; $html =~ s/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 + my $filter = $q->param("filter"); # construct swish query my $sw_q = join(" and ",@s_arr); if (@path_arr && $q->param('show_full')) { - $sw_q .= "and (swishdocpath=\""; + $sw_q .= " and (swishdocpath=\""; $sw_q .= join("\" or swishdocpath=\"",@path_arr); $sw_q .= "\")"; $tmpl->param('full',1); # show full records +# } elsif (@path_arr && $#path_arr == 0) { +# # I will assume that it's a filter since there isn't show_full +# $filter = shift @path_arr; } elsif ($q->param('show_full')) { # just show full path, no path defined $tmpl->param('full',1); @@ -378,6 +390,13 @@ $tmpl->param('full',0); } + if ($filter) { + $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr); + push @persist_vars, "filter"; + $url_params->{'filter'} = $filter; + $url_params_persist->{'filter'} = $filter; + } + my $swish_msg = ' '; # create new swish instance @@ -402,6 +421,17 @@ $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); + # URL parametars for search results + sub cook_url_params { + my $hash = shift || return; + return join("&", map { $_."=".$hash->{$_} } keys %{$hash}); + } + + $tmpl->param('url_params',"?".cook_url_params($url_params)); + $tmpl->param('url_params_paths',"?".cook_url_params($url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); + + + # # build pager # @@ -435,7 +465,8 @@ rank => $result->Property('swishrank') }; - $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full')); + #$r->{html} = back2html($from_utf8->convert($result->Property('html')), cook_url_params($url_params_persist)) if ($q->param('show_full')); + $r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full')); push @pager_data_list, $r; }