--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2006/02/19 20:16:11 404 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2006/03/12 22:34:53 421 @@ -239,13 +239,18 @@ $cond->set_max( $page * $max ); my $result = $self->{est_node}->search($cond, $args->{depth}); + if (! $result) { + $self->{log}->fatal("search didn't return result"); + return; + } my $hits = $result->doc_num; $times->{est} += time() - $t; $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) ); - $log->dumper($result->{hints}, 'result->hints' ); + $self->{hints} = $result->{hints}; + #$log->dumper($self->{hints}, 'original hints' ); # # fetch results @@ -330,6 +335,52 @@ return \@results; } +=head2 hints + + my $hints = $m->hints; + +Return various useful hints about result + +=cut + +sub hints { + my $self = shift; + + unless ($self->{hints}) { + $self->{log}->fatal("no hints found!"); + return; + } + + my $hints; + + while (my ($key,$val) = each %{ $self->{hints} }) { + + #$self->{log}->debug("current hint $key = $val"); + + if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) { + $hints->{ lc($key) } = $val; + } elsif ($key =~ m/^HINT#/) { + my ($word,$count) = split(/\t/,$val,2); + $hints->{words}->{$word} = $count; + } elsif ($key =~ m/^LINK#/) { + my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7); + if ($url =~ m#/node/(.+)$#) { + $hints->{node}->{$1} = $results; + } else { + $self->{log}->debug("url $url doesn't have /node/ in it!"); + } + } else { + $self->{log}->debug("unknown hint $key = $val"); + } + + } + + $self->{log}->dumper($hints, 'model hints' ); + + return $hints; +} + + =head2 record my $html = $m->record( @@ -422,6 +473,7 @@ my $node = $1; $self->setup_site( $node ); $self->{est_node}->_set_info; + $label = decode('UTF-8', $label); push @nodes, { name => $node, label => $label, @@ -440,9 +492,6 @@ return @nodes; } -=cut - - =head2 save_html $m->save_html( '/full/path/to/file', $content ); @@ -514,6 +563,10 @@ =cut +# Escape <, >, & and ", and to produce valid XML +my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); +my $escape_re = join '|' => keys %escape; + sub apply { my $self = shift; @@ -561,9 +614,12 @@ if (ref($v) eq 'ARRAY') { if ($#{$v} == 0) { $v = $v->[0]; + $v =~ s/($escape_re)/$escape{$1}/g; } else { $join = $default_delimiter->{$type} unless defined($join); - $v = join($join, @{$v}); + $v = join($join, map { + s/($escape_re)/$escape{$1}/g; + } @{$v}); } } else { warn("TT filter $type(): field $name values aren't ARRAY, ignoring");