153 |
my $self = shift; |
my $self = shift; |
154 |
|
|
155 |
my $site = shift || $self->{defaultnode}; |
my $site = shift || $self->{defaultnode}; |
156 |
|
if (! $site) { |
157 |
|
$self->{log}->warn("not changing site from " . $self->{est_node}->{url}); |
158 |
|
return; |
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 |
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 |
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; |
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 |
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#/) { |
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 |
|
|
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 |
|
|
453 |
my $site = shift; |
my $site = shift || $self->{defaultnode}; |
454 |
|
|
455 |
$self->{log}->debug("list_nodes use site $site"); |
# cache? |
456 |
|
if ($nodes_list->{$site} && ref($nodes_list->{$site} eq 'ARRAY')) { |
457 |
|
$self->{log}->debug("list_nodes for site $site and returns from cache"); |
458 |
|
return @{ $nodes_list->{$site} }; |
459 |
|
}; |
460 |
|
|
461 |
|
$self->{log}->debug("list_nodes for site $site"); |
462 |
|
|
463 |
$self->setup_site( $site ); |
$self->setup_site( $site ); |
464 |
|
|
485 |
my $node = $1; |
my $node = $1; |
486 |
$self->setup_site( $node ); |
$self->setup_site( $node ); |
487 |
$self->{est_node}->_set_info; |
$self->{est_node}->_set_info; |
488 |
|
$label = decode('UTF-8', $label); |
489 |
push @nodes, { |
push @nodes, { |
490 |
name => $node, |
name => $node, |
491 |
label => $label, |
label => $label, |
501 |
|
|
502 |
$self->{log}->dumper( \@nodes, 'nodes' ); |
$self->{log}->dumper( \@nodes, 'nodes' ); |
503 |
|
|
504 |
|
$nodes_list->{$site} = \@nodes; |
505 |
|
|
506 |
return @nodes; |
return @nodes; |
507 |
} |
} |
508 |
|
|
|
=cut |
|
|
|
|
|
|
|
509 |
=head2 save_html |
=head2 save_html |
510 |
|
|
511 |
$m->save_html( '/full/path/to/file', $content ); |
$m->save_html( '/full/path/to/file', $content ); |
577 |
|
|
578 |
=cut |
=cut |
579 |
|
|
580 |
|
# Escape <, >, & and ", and to produce valid XML |
581 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
582 |
|
my $escape_re = join '|' => keys %escape; |
583 |
|
|
584 |
sub apply { |
sub apply { |
585 |
my $self = shift; |
my $self = shift; |
586 |
|
|
628 |
if (ref($v) eq 'ARRAY') { |
if (ref($v) eq 'ARRAY') { |
629 |
if ($#{$v} == 0) { |
if ($#{$v} == 0) { |
630 |
$v = $v->[0]; |
$v = $v->[0]; |
631 |
|
$v =~ s/($escape_re)/$escape{$1}/g; |
632 |
} else { |
} else { |
633 |
$join = $default_delimiter->{$type} unless defined($join); |
$join = $default_delimiter->{$type} unless defined($join); |
634 |
$v = join($join, @{$v}); |
$v = join($join, map { |
635 |
|
s/($escape_re)/$escape{$1}/g; |
636 |
|
} @{$v}); |
637 |
} |
} |
638 |
} else { |
} else { |
639 |
warn("TT filter $type(): field $name values aren't ARRAY, ignoring"); |
warn("TT filter $type(): field $name values aren't ARRAY, ignoring"); |