--- trunk/WebPac.pm 2005/02/21 22:21:53 675 +++ trunk/WebPac.pm 2006/04/13 19:31:43 725 @@ -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,6 +191,7 @@ foreach my $v (@persist_vars) { foreach my $val ($q->param($v)) { next if (! $val || $val eq ''); + $val =~ s/"/"/g; $hidden_vars .= ''."\n"; $hidden_search .= ''."\n" if ($v ne "rm"); } @@ -227,6 +233,12 @@ my $q = $self->query(); + # submit was reset? + if ($q->param('reset')) { + $q->delete_all; + return $self->show_search_form(); + } + # load template for this page my @s_arr; # all queries are located here @@ -235,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 @@ -263,17 +279,22 @@ # 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); + + my @v; foreach my $v ($q->url_param("v$i")) { - push @url_params,"v$i=$v"; - push @url_params_persist,"v$i=$v" if ($persist); + # escape quotes so that phrase search work + $v =~ s/"/%22/g; + push @v, $v; } + $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 @@ -323,6 +344,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; } @@ -333,8 +355,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); @@ -369,6 +393,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 @@ -393,6 +424,26 @@ $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 { + my $var = $_; + if (ref($hash->{$var}) eq 'ARRAY') { + join('&', + map { $var.'='.$_ } @{$hash->{$var}} + ); + } else { + $var."=".$hash->{$var}; + } + } 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 # @@ -426,7 +477,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; } @@ -476,6 +528,7 @@ $tmpl->param('field',$field); $tmpl->param('limit',$limit); $tmpl->param('total',$total); + $tmpl->param('filter',$filter); # FIXME I should set offset and leave out limit from fetch!! # if (! $q->param("PAGER_offset") {