--- trunk/WebPac.pm 2005/02/21 22:21:53 675 +++ trunk/WebPac.pm 2005/04/30 15:46:03 698 @@ -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 @@ -267,6 +279,8 @@ push @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); } @@ -323,6 +337,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 +348,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 +386,13 @@ $tmpl->param('full',0); } + if ($filter) { + $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr); + push @persist_vars, "filter"; + push @url_params, "filter=$filter"; + push @url_params_persist, "filter=$filter"; + } + my $swish_msg = ' '; # create new swish instance @@ -393,6 +417,12 @@ $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 + $tmpl->param('url_params',"?".join("&",@url_params)); + $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); + + + # # build pager # @@ -476,6 +506,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") {