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}, 'hints' ); |
254 |
|
|
255 |
# |
# |
256 |
# fetch results |
# fetch results |
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 |
|
if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) { |
359 |
|
$hints->{ lc($key) } = $val; |
360 |
|
} elsif ($key =~ m/^HINT#/) { |
361 |
|
my ($word,$count) = split(/\t/,$val,2); |
362 |
|
$hints->{words}->{$word} = $count; |
363 |
|
} elsif ($key =~ m/^LINK#/) { |
364 |
|
my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7); |
365 |
|
if ($url =~ m#/node/(.+)$#) { |
366 |
|
$hints->{node}->{$1} = $results; |
367 |
|
} |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
return $hints; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
=head2 record |
=head2 record |
376 |
|
|
377 |
my $html = $m->record( |
my $html = $m->record( |
556 |
|
|
557 |
=cut |
=cut |
558 |
|
|
559 |
|
# Escape <, >, & and ", and to produce valid XML |
560 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
561 |
|
my $escape_re = join '|' => keys %escape; |
562 |
|
|
563 |
sub apply { |
sub apply { |
564 |
my $self = shift; |
my $self = shift; |
565 |
|
|
607 |
if (ref($v) eq 'ARRAY') { |
if (ref($v) eq 'ARRAY') { |
608 |
if ($#{$v} == 0) { |
if ($#{$v} == 0) { |
609 |
$v = $v->[0]; |
$v = $v->[0]; |
610 |
|
$v =~ s/($escape_re)/$escape{$1}/g; |
611 |
} else { |
} else { |
612 |
$join = $default_delimiter->{$type} unless defined($join); |
$join = $default_delimiter->{$type} unless defined($join); |
613 |
$v = join($join, @{$v}); |
$v = join($join, map { |
614 |
|
s/($escape_re)/$escape{$1}/g; |
615 |
|
} @{$v}); |
616 |
} |
} |
617 |
} else { |
} else { |
618 |
warn("TT filter $type(): field $name values aren't ARRAY, ignoring"); |
warn("TT filter $type(): field $name values aren't ARRAY, ignoring"); |