/[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 404 by dpavlin, Sun Feb 19 20:16:11 2006 UTC revision 421 by dpavlin, Sun Mar 12 22:34:53 2006 UTC
# Line 239  sub search { Line 239  sub search {
239          $cond->set_max( $page * $max );          $cond->set_max( $page * $max );
240    
241          my $result = $self->{est_node}->search($cond, $args->{depth});          my $result = $self->{est_node}->search($cond, $args->{depth});
242            if (! $result) {
243                    $self->{log}->fatal("search didn't return result");
244                    return;
245            }
246          my $hits = $result->doc_num;          my $hits = $result->doc_num;
247    
248          $times->{est} += time() - $t;          $times->{est} += time() - $t;
249    
250          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );
251    
252          $log->dumper($result->{hints}, 'result->hints' );          $self->{hints} = $result->{hints};
253            #$log->dumper($self->{hints}, 'original hints' );
254    
255          #          #
256          # fetch results          # fetch results
# Line 330  sub search { Line 335  sub search {
335          return \@results;          return \@results;
336  }  }
337    
338    =head2 hints
339    
340      my $hints = $m->hints;
341    
342    Return various useful hints about result
343    
344    =cut
345    
346    sub hints {
347            my $self = shift;
348    
349            unless ($self->{hints}) {
350                    $self->{log}->fatal("no hints found!");
351                    return;
352            }
353    
354            my $hints;
355    
356            while (my ($key,$val) = each %{ $self->{hints} }) {
357    
358                    #$self->{log}->debug("current hint $key = $val");
359    
360                    if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) {
361                            $hints->{ lc($key) } = $val;
362                    } elsif ($key =~ m/^HINT#/) {
363                            my ($word,$count) = split(/\t/,$val,2);
364                            $hints->{words}->{$word} = $count;
365                    } elsif ($key =~ m/^LINK#/) {
366                            my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7);
367                            if ($url =~ m#/node/(.+)$#) {
368                                    $hints->{node}->{$1} = $results;
369                            } else {
370                                    $self->{log}->debug("url $url doesn't have /node/ in it!");
371                            }
372                    } else {
373                            $self->{log}->debug("unknown hint $key = $val");
374                    }
375    
376            }
377    
378            $self->{log}->dumper($hints, 'model hints' );
379    
380            return $hints;
381    }
382    
383    
384  =head2 record  =head2 record
385    
386    my $html = $m->record(    my $html = $m->record(
# Line 422  sub list_nodes { Line 473  sub list_nodes {
473                          my $node = $1;                          my $node = $1;
474                          $self->setup_site( $node );                          $self->setup_site( $node );
475                          $self->{est_node}->_set_info;                          $self->{est_node}->_set_info;
476                            $label = decode('UTF-8', $label);
477                          push @nodes, {                          push @nodes, {
478                                  name => $node,                                  name => $node,
479                                  label => $label,                                  label => $label,
# Line 440  sub list_nodes { Line 492  sub list_nodes {
492          return @nodes;          return @nodes;
493  }  }
494    
 =cut  
   
   
495  =head2 save_html  =head2 save_html
496    
497    $m->save_html( '/full/path/to/file', $content );    $m->save_html( '/full/path/to/file', $content );
# Line 514  It also has follwing template toolikit f Line 563  It also has follwing template toolikit f
563    
564  =cut  =cut
565    
566    # Escape <, >, & and ", and to produce valid XML
567    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  
568    my $escape_re  = join '|' => keys %escape;
569    
570  sub apply {  sub apply {
571          my $self = shift;          my $self = shift;
572    
# Line 561  C<d('FieldName','delimiter')>, where C<d Line 614  C<d('FieldName','delimiter')>, where C<d
614                          if (ref($v) eq 'ARRAY') {                          if (ref($v) eq 'ARRAY') {
615                                  if ($#{$v} == 0) {                                  if ($#{$v} == 0) {
616                                          $v = $v->[0];                                          $v = $v->[0];
617                                            $v =~ s/($escape_re)/$escape{$1}/g;
618                                  } else {                                  } else {
619                                          $join = $default_delimiter->{$type} unless defined($join);                                          $join = $default_delimiter->{$type} unless defined($join);
620                                          $v = join($join, @{$v});                                          $v = join($join, map {
621                                                    s/($escape_re)/$escape{$1}/g;
622                                            } @{$v});
623                                  }                                  }
624                          } else {                          } else {
625                                  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.404  
changed lines
  Added in v.421

  ViewVC Help
Powered by ViewVC 1.1.26