/[webpac]/trunk/WebPac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/WebPac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 639 by dpavlin, Wed Jan 19 22:34:31 2005 UTC revision 685 by dpavlin, Tue Mar 1 19:27:13 2005 UTC
# Line 12  use Text::Unaccent; Line 12  use Text::Unaccent;
12  use Data::Pageset;  use Data::Pageset;
13    
14  use lib '..';  use lib '..';
15  use index_DBI_cache;  use index_DBI_filter;
16  use back2html;  use back2html;
17    
18    
# Line 148  sub make_pager($$$) { Line 148  sub make_pager($$$) {
148    
149    
150          foreach my $p (@{$pager->pages_in_set()}) {          foreach my $p (@{$pager->pages_in_set()}) {
151                  next if ($p < 0);                  next if ($p <= 0);
152                  if($p == $pager->current_page()) {                  if($p == $pager->current_page()) {
153                          $pager_jump .= "<b>$p</b> ";                          $pager_jump .= "<b>$p</b> ";
154                  } else {                  } else {
# Line 182  sub make_pager_vars { Line 182  sub make_pager_vars {
182          my $tmpl = shift @_;          my $tmpl = shift @_;
183          my @persist_vars = @_;          my @persist_vars = @_;
184          my $hidden_vars = '';          my $hidden_vars = '';
185            my $hidden_search = '';
186          foreach my $v (@persist_vars) {          foreach my $v (@persist_vars) {
187                  foreach my $val ($q->param($v)) {                  foreach my $val ($q->param($v)) {
188                          next if (! $val || $val eq '');                          next if (! $val || $val eq '');
189                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
190                            $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");
191                  }                  }
192          }          }
193    
194          $tmpl->param('PAGER_HIDDEN', $hidden_vars);          $tmpl->param('PAGER_HIDDEN', $hidden_vars);
195            $tmpl->param('SEARCH_HIDDEN', $hidden_search);
196          $tmpl->param('PAGER_JAVASCRIPT', qq#          $tmpl->param('PAGER_JAVASCRIPT', qq#
197  <SCRIPT LANGUAGE="Javascript">  <SCRIPT LANGUAGE="Javascript">
198  <!-- Begin  <!-- Begin
# Line 224  sub show_results_list { Line 227  sub show_results_list {
227    
228          my $q = $self->query();          my $q = $self->query();
229    
230            # submit was reset?
231            if ($q->param('reset')) {
232                    $q->delete_all;
233                    return $self->show_search_form();
234            }
235    
236          # load template for this page          # load template for this page
237    
238          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
# Line 264  sub show_results_list { Line 273  sub show_results_list {
273                  push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);                  push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);
274    
275                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
276                            # escape quotes so that phrase search work
277                            $v =~ s/"/%22/g;
278                          push @url_params,"v$i=$v";                          push @url_params,"v$i=$v";
279                          push @url_params_persist,"v$i=$v" if ($persist);                          push @url_params_persist,"v$i=$v" if ($persist);
280                  }                  }
# Line 328  sub show_results_list { Line 339  sub show_results_list {
339                  push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";                  push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";
340          }          }
341    
342          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0);
343    
344          $tmpl->param('url_params',"?".join("&",@url_params));          $tmpl->param('url_params',"?".join("&",@url_params));
345    
# Line 345  sub show_results_list { Line 356  sub show_results_list {
356                  push @persist_vars, "sort";                  push @persist_vars, "sort";
357          }          }
358    
359            my $sortby = $q->param("sortby");
360            if ($sortby) {
361                    $sort = $sortby;
362                    push @persist_vars, "sortby";
363            }
364            $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
365    
366          # construct swish query          # construct swish query
367          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
368          if (@path_arr && $q->param('show_full')) {          if (@path_arr && $q->param('show_full')) {
# Line 359  sub show_results_list { Line 377  sub show_results_list {
377                  $tmpl->param('full',0);                  $tmpl->param('full',0);
378          }          }
379    
380            my $swish_msg = ' ';
381    
382          # create new swish instance          # create new swish instance
383          my $swish = SWISH::API->new($INDEX);          my $swish = SWISH::API->new($INDEX);
384          die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
385    
386          # execute query and get number of results from SWISH-E          # execute query and get number of results from SWISH-E
387          my $search = $swish->New_Search_Object;          my $search = $swish->New_Search_Object;
# Line 369  sub show_results_list { Line 389  sub show_results_list {
389          $search->SetSort($sort);          $search->SetSort($sort);
390    
391          my $results = $search->Execute($sw_q);          my $results = $search->Execute($sw_q);
392          die $swish->ErrorString.": ".$swish->LastErrorMsg if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
393    
394          my $hits = $results->Hits;          my $hits = $results->Hits;
395    
396          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
397          $tmpl->param('search',$sw_q);          my $search_msg = $sw_q;
398            $search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg);
399            $tmpl->param('search', $search_msg);
400    
401          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
402          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
# Line 438  sub show_index { Line 460  sub show_index {
460          my $field = $q->param("f$i");          my $field = $q->param("f$i");
461          my $limit = $q->param("v$i");          my $limit = $q->param("v$i");
462    
463            my $filter = $q->param("filter");
464    
465          my $html;          my $html;
466    
467          my $index = new index_DBI(          my $index = new index_DBI(
# Line 447  sub show_index { Line 471  sub show_index {
471                  $cfg_global->val('global', 'dbi_passwd') || ''                  $cfg_global->val('global', 'dbi_passwd') || ''
472          );          );
473    
474          my $total = $index->count($field,$limit);          my $total = $index->count($field,$limit,$filter);
475    
476          if (! $total) {          if (! defined($total)) {
477                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
478                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
479                  $html = $tmpl->output;                  $html = $tmpl->output;
480                  return $html;                  return $html;
481          }          }
482    
483          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1);          my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0);
484          $tmpl->param('field',$field);          $tmpl->param('field',$field);
485          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
486          $tmpl->param('total',$total);          $tmpl->param('total',$total);
487            $tmpl->param('filter',$filter);
488    
489  # FIXME I should set offset and leave out limit from fetch!!  # FIXME I should set offset and leave out limit from fetch!!
490  #       if (! $q->param("PAGER_offset") {  #       if (! $q->param("PAGER_offset") {
# Line 482  sub show_index { Line 507  sub show_index {
507          make_pager($q, $tmpl, $pager);          make_pager($q, $tmpl, $pager);
508          make_pager_vars($q, $tmpl, @persist_vars);          make_pager_vars($q, $tmpl, @persist_vars);
509    
510          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);
511          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
512    
513          return in_template($q,$tmpl->output);          return in_template($q,$tmpl->output);

Legend:
Removed from v.639  
changed lines
  Added in v.685

  ViewVC Help
Powered by ViewVC 1.1.26