don't die if ISIS database is not found, just go to next one
[webpac] / WebPac.pm
index c187dee..4afc2c2 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;
 
 
@@ -183,11 +183,14 @@ sub make_pager_vars {
        my @persist_vars = @_;
        my $hidden_vars = '';
        foreach my $v (@persist_vars) {
-               $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$q->param($v).'"/>'."\n";
+               foreach my $val ($q->param($v)) {
+                       next if (! $val || $val eq '');
+                       $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
+               }
        }
 
        $tmpl->param('PAGER_HIDDEN', $hidden_vars);
-       $tmpl->param('PAGER_JAVASCRIPT', qq{
+       $tmpl->param('PAGER_JAVASCRIPT', qq#
 <SCRIPT LANGUAGE="Javascript">
 <!-- Begin
        // dummy emulator for HTML::Pager templates
@@ -196,7 +199,7 @@ sub make_pager_vars {
        }
 // End -->
 </script>  
-       });
+       #);
 }
 
 #--------------------------------------------------------------------------
@@ -228,26 +231,47 @@ sub show_results_list {
        my @path_arr = $q->param('path');
        my $full = $q->param('full');
 
-       my @persist_vars = ( 'rm' );
+       my @persist_vars = ( 'rm', 'persist_search' );
        my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) );
 
+       my @persist_search_vars;
+       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");
+       }
+
        # support parametars "f" and "v" for start
-       for(my $i = ""; $i <=30; $i++) {
+       for(my $i = 0; $i <=30; $i++) {
+
+               $i = '' if ($i == 0);
 
                return show_index($self, $i) if ($q->param("f".$i."_index"));
 
-               next if (! $q->param("v$i"));
+               next if (! $q->param("v$i") || $q->param("v$i") eq '');
                next if (! $q->param("f$i"));
 
+               my $persist = grep(/^$i$/,@persist_search_vars);
+       
                push @persist_vars, "f$i";
                push @persist_vars, "v$i";
                push @persist_vars, "e$i" if ($q->param("e$i"));
 
+               # 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);
+
                foreach my $v ($q->url_param("v$i")) {
                        push @url_params,"v$i=$v";
+                       push @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");
                }
-               push @url_params,"e$i=".$q->url_param("e$i");
 
                my $wc="*";     # swish wildcard
                $wc="" if ($i eq "");   # don't apply wildcard on field 0
@@ -268,8 +292,9 @@ sub show_results_list {
 
                        # filed e[nr] is exact match bitmask
                        # 1 = beginning, 2=end, 3=both
-                       $pre = '"xxbxx ' if ($q->param("e$i") & 1);
-                       $post = ' xxexx"' if ($q->param("e$i") & 2);
+                       my $exact_flag = $q->param("e$i") || 0;
+                       $pre = '"xxbxx ' if ($exact_flag & 1);
+                       $post = ' xxexx"' if ($exact_flag & 2);
                        # add qotes on other side
                        if ($q->param("e$i")) {
                                $pre = '"' if (! $pre);
@@ -336,7 +361,7 @@ sub show_results_list {
 
        # create new swish instance
        my $swish = SWISH::API->new($INDEX);
-       $swish->AbortLastError if $swish->Error;
+       die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;
 
        # execute query and get number of results from SWISH-E
        my $search = $swish->New_Search_Object;
@@ -344,7 +369,7 @@ sub show_results_list {
        $search->SetSort($sort);
 
        my $results = $search->Execute($sw_q);
-       $swish->AbortLastError if $swish->Error;
+       die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;
 
        my $hits = $results->Hits;
 
@@ -387,7 +412,7 @@ sub show_results_list {
                        rank => $result->Property('swishrank')
                };
 
-               $r->{html} = back2html($from_utf8->convert($result->Property('html'))) if ($q->param('show_full'));
+               $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full'));
 
                push @pager_data_list, $r;
        }
@@ -413,6 +438,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(
@@ -422,9 +449,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;
@@ -457,7 +484,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);