filter to checked documents
[webpac] / WebPac.pm
index e4d6448..94d47d5 100644 (file)
--- a/WebPac.pm
+++ b/WebPac.pm
@@ -12,7 +12,7 @@ use Text::Unaccent;
 use Data::Pageset;
 
 use lib '..';
-use index_DBI_cache;
+use index_DBI_filter;
 use back2html;
 
 
@@ -148,7 +148,7 @@ sub make_pager($$$) {
 
 
        foreach my $p (@{$pager->pages_in_set()}) {
-               next if ($p < 0);
+               next if ($p <= 0);
                if($p == $pager->current_page()) {
                        $pager_jump .= "<b>$p</b> ";
                } else {
@@ -345,6 +345,13 @@ sub show_results_list {
                push @persist_vars, "sort";
        }
 
+       my $sortby = $q->param("sortby");
+       if ($sortby) {
+               $sort = $sortby;
+               push @persist_vars, "sortby";
+       }
+       $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
+
        # construct swish query
        my $sw_q = join(" and ",@s_arr);
        if (@path_arr && $q->param('show_full')) {
@@ -359,9 +366,11 @@ sub show_results_list {
                $tmpl->param('full',0);
        }
 
+       my $swish_msg = ' ';
+
        # create new swish instance
        my $swish = SWISH::API->new($INDEX);
-       die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;
+       $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
 
        # execute query and get number of results from SWISH-E
        my $search = $swish->New_Search_Object;
@@ -369,12 +378,14 @@ sub show_results_list {
        $search->SetSort($sort);
 
        my $results = $search->Execute($sw_q);
-       die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;
+       $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
 
        my $hits = $results->Hits;
 
        $tmpl->param('hits',$hits);
-       $tmpl->param('search',$sw_q);
+       my $search_msg = $sw_q;
+       $search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg);
+       $tmpl->param('search', $search_msg);
 
        $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
        $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
@@ -438,6 +449,8 @@ sub show_index {
        my $field = $q->param("f$i");
        my $limit = $q->param("v$i");
 
+       my $filter = $q->param("filter");
+
        my $html;
 
        my $index = new index_DBI(
@@ -447,9 +460,9 @@ sub show_index {
                $cfg_global->val('global', 'dbi_passwd') || ''
        );
 
-       my $total = $index->count($field,$limit);
+       my $total = $index->count($field,$limit,$filter);
 
-       if (! $total) {
+       if (! defined($total)) {
                my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
                $tmpl->param('field',$field);
                $html = $tmpl->output;
@@ -482,7 +495,7 @@ sub show_index {
        make_pager($q, $tmpl, $pager);
        make_pager_vars($q, $tmpl, @persist_vars);
 
-       my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page);
+       my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page, $filter);
        $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
 
        return in_template($q,$tmpl->output);