/[webpac2]/Webpacus/lib/Webpacus/Model/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 /Webpacus/lib/Webpacus/Model/WebPAC.pm

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

revision 405 by dpavlin, Sun Feb 19 22:40:40 2006 UTC revision 422 by dpavlin, Sun Mar 19 22:57:05 2006 UTC
# Line 152  to C<defaultnode> from configuration. Line 152  to C<defaultnode> from configuration.
152  sub setup_site {  sub setup_site {
153          my $self = shift;          my $self = shift;
154    
155          my $site = shift || $self->{defaultnode};          my $site = shift;
156            if (! $site) {
157                    $site = $self->{defaultnode};
158                    $self->{log}->warn("using default site $site");
159            }
160    
161          $self->{log}->fatal("setup_site can't find site or defaultnode") unless ($site);          $self->{log}->fatal("setup_site can't find site or defaultnode") unless ($site);
162    
163          my $url = $self->{masterurl} . '/node/' . $site;          my $url = $self->{masterurl} . '/node/' . $site;
164          $self->{est_node}->set_url( $url );          $self->{est_node}->set_url( $url );
165          $self->{log}->debug("setup_site $site using $url");          $self->{log}->debug("setup_site '$site' using $url");
166  }  }
167    
168  =head2 search  =head2 search
# Line 211  sub search { Line 215  sub search {
215          }          }
216          $args->{depth} ||= 0;          $args->{depth} ||= 0;
217    
218          $log->debug("searching for maximum $args->{max} results using depth $args->{depth} phrase: ", $query || '[none]');          $log->debug("searching " . $self->{est_node}->{url} . " max: $args->{max} depth: $args->{depth} phrase: " . ($query || '[none]') );
219    
220          #          #
221          # construct condition for Hyper Estraier          # construct condition for Hyper Estraier
# Line 239  sub search { Line 243  sub search {
243          $cond->set_max( $page * $max );          $cond->set_max( $page * $max );
244    
245          my $result = $self->{est_node}->search($cond, $args->{depth});          my $result = $self->{est_node}->search($cond, $args->{depth});
246            if (! $result) {
247                    $self->{log}->fatal("search didn't return result");
248                    return;
249            }
250          my $hits = $result->doc_num;          my $hits = $result->doc_num;
251    
252          $times->{est} += time() - $t;          $times->{est} += time() - $t;
# Line 246  sub search { Line 254  sub search {
254          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );
255    
256          $self->{hints} = $result->{hints};          $self->{hints} = $result->{hints};
257          $log->dumper($self->{hints}, 'hints' );          #$log->dumper($self->{hints}, 'original hints' );
258    
259          #          #
260          # fetch results          # fetch results
# Line 351  sub hints { Line 359  sub hints {
359    
360          while (my ($key,$val) = each %{ $self->{hints} }) {          while (my ($key,$val) = each %{ $self->{hints} }) {
361    
362                    #$self->{log}->debug("current hint $key = $val");
363    
364                  if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) {                  if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) {
365                          $hints->{ lc($key) } = $val;                          $hints->{ lc($key) } = $val;
366                  } elsif ($key =~ m/^HINT#/) {                  } elsif ($key =~ m/^HINT#/) {
# Line 360  sub hints { Line 370  sub hints {
370                          my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7);                          my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7);
371                          if ($url =~ m#/node/(.+)$#) {                          if ($url =~ m#/node/(.+)$#) {
372                                  $hints->{node}->{$1} = $results;                                  $hints->{node}->{$1} = $results;
373                            } else {
374                                    $self->{log}->debug("url $url doesn't have /node/ in it!");
375                          }                          }
376                    } else {
377                            $self->{log}->debug("unknown hint $key = $val");
378                  }                  }
379    
380          }          }
381    
382            $self->{log}->dumper($hints, 'model hints' );
383    
384          return $hints;          return $hints;
385  }  }
386    
# Line 428  hashes has elements C<name> and C<label> Line 445  hashes has elements C<name> and C<label>
445    
446  =cut  =cut
447    
448    my $nodes_list;
449    
450  sub list_nodes {  sub list_nodes {
451          my $self = shift;          my $self = shift;
452    
# Line 437  sub list_nodes { Line 456  sub list_nodes {
456    
457          $self->setup_site( $site );          $self->setup_site( $site );
458    
459            # cache?
460            return @{ $nodes_list->{$site} } if ($nodes_list->{$site} && ref($nodes_list->{$site} eq 'ARRAY'));
461    
462          my @nodes;          my @nodes;
463    
464          if ($self->{est_node}->doc_num > 0) {          if ($self->{est_node}->doc_num > 0) {
# Line 460  sub list_nodes { Line 482  sub list_nodes {
482                          my $node = $1;                          my $node = $1;
483                          $self->setup_site( $node );                          $self->setup_site( $node );
484                          $self->{est_node}->_set_info;                          $self->{est_node}->_set_info;
485                            $label = decode('UTF-8', $label);
486                          push @nodes, {                          push @nodes, {
487                                  name => $node,                                  name => $node,
488                                  label => $label,                                  label => $label,
# Line 475  sub list_nodes { Line 498  sub list_nodes {
498    
499          $self->{log}->dumper( \@nodes, 'nodes' );          $self->{log}->dumper( \@nodes, 'nodes' );
500    
501            $nodes_list->{$site} = \@nodes;
502    
503          return @nodes;          return @nodes;
504  }  }
505    
 =cut  
   
   
506  =head2 save_html  =head2 save_html
507    
508    $m->save_html( '/full/path/to/file', $content );    $m->save_html( '/full/path/to/file', $content );
# Line 552  It also has follwing template toolikit f Line 574  It also has follwing template toolikit f
574    
575  =cut  =cut
576    
577    # Escape <, >, & and ", and to produce valid XML
578    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  
579    my $escape_re  = join '|' => keys %escape;
580    
581  sub apply {  sub apply {
582          my $self = shift;          my $self = shift;
583    
# Line 599  C<d('FieldName','delimiter')>, where C<d Line 625  C<d('FieldName','delimiter')>, where C<d
625                          if (ref($v) eq 'ARRAY') {                          if (ref($v) eq 'ARRAY') {
626                                  if ($#{$v} == 0) {                                  if ($#{$v} == 0) {
627                                          $v = $v->[0];                                          $v = $v->[0];
628                                            $v =~ s/($escape_re)/$escape{$1}/g;
629                                  } else {                                  } else {
630                                          $join = $default_delimiter->{$type} unless defined($join);                                          $join = $default_delimiter->{$type} unless defined($join);
631                                          $v = join($join, @{$v});                                          $v = join($join, map {
632                                                    s/($escape_re)/$escape{$1}/g;
633                                            } @{$v});
634                                  }                                  }
635                          } else {                          } else {
636                                  warn("TT filter $type(): field $name values aren't ARRAY, ignoring");                                  warn("TT filter $type(): field $name values aren't ARRAY, ignoring");

Legend:
Removed from v.405  
changed lines
  Added in v.422

  ViewVC Help
Powered by ViewVC 1.1.26