--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2006/02/19 20:16:11 404 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2006/02/20 21:48:47 414 @@ -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}, 'hints' ); # # fetch results @@ -330,6 +335,43 @@ 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} }) { + + 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; + } + } + } + + return $hints; +} + + =head2 record my $html = $m->record( @@ -514,6 +556,10 @@ =cut +# Escape <, >, & and ", and to produce valid XML +my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); +my $escape_re = join '|' => keys %escape; + sub apply { my $self = shift; @@ -561,9 +607,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");