/[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 600 by dpavlin, Wed Dec 8 18:24:24 2004 UTC revision 675 by dpavlin, Mon Feb 21 22:21:53 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 '');
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('PAGER_JAVASCRIPT', qq{          $tmpl->param('SEARCH_HIDDEN', $hidden_search);
196            $tmpl->param('PAGER_JAVASCRIPT', qq#
197  <SCRIPT LANGUAGE="Javascript">  <SCRIPT LANGUAGE="Javascript">
198  <!-- Begin  <!-- Begin
199          // dummy emulator for HTML::Pager templates          // dummy emulator for HTML::Pager templates
# Line 198  sub make_pager_vars { Line 202  sub make_pager_vars {
202          }          }
203  // End -->  // End -->
204  </script>    </script>  
205          });          #);
206  }  }
207    
208  #--------------------------------------------------------------------------  #--------------------------------------------------------------------------
# Line 230  sub show_results_list { Line 234  sub show_results_list {
234          my @path_arr = $q->param('path');          my @path_arr = $q->param('path');
235          my $full = $q->param('full');          my $full = $q->param('full');
236    
237          my @persist_vars = ( 'rm' );          my @persist_vars = ( 'rm', 'persist_search' );
238          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) );
239    
240            my @persist_search_vars;
241            my @url_params_persist;
242            if ($q->param("persist_search")) {
243                    @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
244                    push @url_params_persist, "persist_search=".$q->url_param("persist_search");
245                    push @url_params,"persist_search=".$q->url_param("persist_search");
246            }
247    
248          # support parametars "f" and "v" for start          # support parametars "f" and "v" for start
249          for(my $i = ""; $i <=30; $i++) {          for(my $i = 0; $i <=30; $i++) {
250    
251                    $i = '' if ($i == 0);
252    
253                  return show_index($self, $i) if ($q->param("f".$i."_index"));                  return show_index($self, $i) if ($q->param("f".$i."_index"));
254    
255                  next if (! $q->param("v$i"));                  next if (! $q->param("v$i") || $q->param("v$i") eq '');
256                  next if (! $q->param("f$i"));                  next if (! $q->param("f$i"));
257    
258                    my $persist = grep(/^$i$/,@persist_search_vars);
259            
260                  push @persist_vars, "f$i";                  push @persist_vars, "f$i";
261                  push @persist_vars, "v$i";                  push @persist_vars, "v$i";
262                  push @persist_vars, "e$i" if ($q->param("e$i"));                  push @persist_vars, "e$i" if ($q->param("e$i"));
263    
264                    # create url parametars (and persistent ones)
265    
266                  push @url_params,"f$i=".$q->url_param("f$i");                  push @url_params,"f$i=".$q->url_param("f$i");
267                    push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);
268    
269                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
270                          push @url_params,"v$i=$v";                          push @url_params,"v$i=$v";
271                            push @url_params_persist,"v$i=$v" if ($persist);
272                    }
273    
274                    if ($q->param("e$i")) {
275                            push @url_params,"e$i=".$q->url_param("e$i");
276    #                       push @url_params_persist,"e$i=".$q->url_param("e$i");
277                  }                  }
                 push @url_params,"e$i=".$q->url_param("e$i");  
278    
279                  my $wc="*";     # swish wildcard                  my $wc="*";     # swish wildcard
280                  $wc="" if ($i eq "");   # don't apply wildcard on field 0                  $wc="" if ($i eq "");   # don't apply wildcard on field 0
# Line 270  sub show_results_list { Line 295  sub show_results_list {
295    
296                          # filed e[nr] is exact match bitmask                          # filed e[nr] is exact match bitmask
297                          # 1 = beginning, 2=end, 3=both                          # 1 = beginning, 2=end, 3=both
298                          $pre = '"xxbxx ' if ($q->param("e$i") & 1);                          my $exact_flag = $q->param("e$i") || 0;
299                          $post = ' xxexx"' if ($q->param("e$i") & 2);                          $pre = '"xxbxx ' if ($exact_flag & 1);
300                            $post = ' xxexx"' if ($exact_flag & 2);
301                          # add qotes on other side                          # add qotes on other side
302                          if ($q->param("e$i")) {                          if ($q->param("e$i")) {
303                                  $pre = '"' if (! $pre);                                  $pre = '"' if (! $pre);
# Line 305  sub show_results_list { Line 331  sub show_results_list {
331                  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).")";
332          }          }
333    
334          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);
335    
336          $tmpl->param('url_params',"?".join("&",@url_params));          $tmpl->param('url_params',"?".join("&",@url_params));
337    
# Line 322  sub show_results_list { Line 348  sub show_results_list {
348                  push @persist_vars, "sort";                  push @persist_vars, "sort";
349          }          }
350    
351            my $sortby = $q->param("sortby");
352            if ($sortby) {
353                    $sort = $sortby;
354                    push @persist_vars, "sortby";
355            }
356            $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
357    
358          # construct swish query          # construct swish query
359          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
360          if (@path_arr) {          if (@path_arr && $q->param('show_full')) {
361                  $sw_q .= "and (swishdocpath=\"";                  $sw_q .= "and (swishdocpath=\"";
362                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);
363                  $sw_q .= "\")";                  $sw_q .= "\")";
364          }                  $tmpl->param('full',1); # show full records
365            } elsif ($q->param('show_full')) {
         if ($q->param('show_full')) {  
366                  # just show full path, no path defined                  # just show full path, no path defined
367                  $tmpl->param('full',1);                  $tmpl->param('full',1);
368          } else {          } else {
369                  $tmpl->param('full',0);                  $tmpl->param('full',0);
370          }          }
371    
372            my $swish_msg = ' ';
373    
374          # create new swish instance          # create new swish instance
375          my $swish = SWISH::API->new($INDEX);          my $swish = SWISH::API->new($INDEX);
376          $swish->AbortLastError if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
377    
378          # execute query and get number of results from SWISH-E          # execute query and get number of results from SWISH-E
379          my $search = $swish->New_Search_Object;          my $search = $swish->New_Search_Object;
# Line 347  sub show_results_list { Line 381  sub show_results_list {
381          $search->SetSort($sort);          $search->SetSort($sort);
382    
383          my $results = $search->Execute($sw_q);          my $results = $search->Execute($sw_q);
384          $swish->AbortLastError if $swish->Error;          $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
385    
386          my $hits = $results->Hits;          my $hits = $results->Hits;
387    
388          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
389          $tmpl->param('search',$sw_q);          my $search_msg = $sw_q;
390            $search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg);
391            $tmpl->param('search', $search_msg);
392    
393          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
394          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
# Line 390  sub show_results_list { Line 426  sub show_results_list {
426                          rank => $result->Property('swishrank')                          rank => $result->Property('swishrank')
427                  };                  };
428    
429                  $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'));
430    
431                  push @pager_data_list, $r;                  push @pager_data_list, $r;
432          }          }
# Line 416  sub show_index { Line 452  sub show_index {
452          my $field = $q->param("f$i");          my $field = $q->param("f$i");
453          my $limit = $q->param("v$i");          my $limit = $q->param("v$i");
454    
455            my $filter = $q->param("filter");
456    
457          my $html;          my $html;
458    
459          my $index = new index_DBI(          my $index = new index_DBI(
# Line 425  sub show_index { Line 463  sub show_index {
463                  $cfg_global->val('global', 'dbi_passwd') || ''                  $cfg_global->val('global', 'dbi_passwd') || ''
464          );          );
465    
466          my $total = $index->count($field,$limit);          my $total = $index->count($field,$limit,$filter);
467    
468          if (! $total) {          if (! defined($total)) {
469                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));                  my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
470                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
471                  $html = $tmpl->output;                  $html = $tmpl->output;
472                  return $html;                  return $html;
473          }          }
474    
475          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);
476          $tmpl->param('field',$field);          $tmpl->param('field',$field);
477          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
478          $tmpl->param('total',$total);          $tmpl->param('total',$total);
# Line 460  sub show_index { Line 498  sub show_index {
498          make_pager($q, $tmpl, $pager);          make_pager($q, $tmpl, $pager);
499          make_pager_vars($q, $tmpl, @persist_vars);          make_pager_vars($q, $tmpl, @persist_vars);
500    
501          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);
502          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);          $tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
503    
504          return in_template($q,$tmpl->output);          return in_template($q,$tmpl->output);

Legend:
Removed from v.600  
changed lines
  Added in v.675

  ViewVC Help
Powered by ViewVC 1.1.26