12 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
13 |
use Encode qw/encode decode from_to/; |
use Encode qw/encode decode from_to/; |
14 |
use Template; |
use Template; |
|
use Data::Dumper; |
|
15 |
|
|
16 |
=head1 NAME |
=head1 NAME |
17 |
|
|
65 |
|
|
66 |
$est_cfg->{encoding} = $est_cfg->{catalyst_encoding} || $c->config->{catalyst_encoding} or $c->log->fatal("can't find catalyst_encoding"); |
$est_cfg->{encoding} = $est_cfg->{catalyst_encoding} || $c->config->{catalyst_encoding} or $c->log->fatal("can't find catalyst_encoding"); |
67 |
|
|
68 |
$log->debug("using config:" . Dumper($est_cfg) ); |
$log->dumper($est_cfg, 'est_cfg'); |
69 |
|
|
70 |
if (! $est_cfg->{database}) { |
if (! $est_cfg->{database}) { |
71 |
my $defaultnode = $est_cfg->{defaultnode} || $log->logdie("can't find defaultnode in estraier configuration"); |
my $defaultnode = $est_cfg->{defaultnode} || $log->logdie("can't find defaultnode in estraier configuration"); |
88 |
# save config parametars in object |
# save config parametars in object |
89 |
foreach my $f (qw/ |
foreach my $f (qw/ |
90 |
db_path template_path hits_on_page webpac_encoding defaultdepth |
db_path template_path hits_on_page webpac_encoding defaultdepth |
91 |
masterurl |
masterurl defaultnode |
92 |
/) { |
/) { |
93 |
$self->{$f} = $c->config->{hyperestraier}->{$f} || |
$self->{$f} = $c->config->{hyperestraier}->{$f} || |
94 |
$c->config->{webpac}->{$f}; |
$c->config->{webpac}->{$f}; |
144 |
|
|
145 |
$self->setup_site('site_name'); |
$self->setup_site('site_name'); |
146 |
|
|
147 |
Change node URL and database name according to site name (if available) |
Change node URL and database name according to site name (if available) or fallback |
148 |
|
to C<defaultnode> from configuration. |
149 |
|
|
150 |
=cut |
=cut |
151 |
|
|
152 |
sub setup_site { |
sub setup_site { |
153 |
my $self = shift; |
my $self = shift; |
154 |
|
|
155 |
my $site = shift || return; |
my $site = shift || $self->{defaultnode}; |
156 |
|
|
157 |
|
$self->{log}->fatal("setup_site can't find site or defaultnode") unless ($site); |
158 |
|
|
159 |
my $url = $self->{masterurl} . '/node/' . $site; |
my $url = $self->{masterurl} . '/node/' . $site; |
160 |
$self->{est_node}->set_url( $url ); |
$self->{est_node}->set_url( $url ); |
161 |
$self->{log}->debug("setup_site $site"); |
$self->{log}->debug("setup_site $site using $url"); |
162 |
} |
} |
163 |
|
|
164 |
=head2 search |
=head2 search |
187 |
|
|
188 |
my $log = $self->{log}; |
my $log = $self->{log}; |
189 |
|
|
190 |
$log->debug("search args: " . Dumper( $args )); |
$log->dumper($args, 'args'); |
191 |
|
|
192 |
my $query = $args->{phrase} || $log->warn("no query phrase") && return; |
my $query = $args->{phrase} || $log->warn("no query phrase") && return; |
193 |
|
|
245 |
|
|
246 |
$log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) ); |
$log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) ); |
247 |
|
|
248 |
$log->debug( "hints: " . Dumper($result->{hints}) ); |
$log->dumper($result->{hints}, 'result->hints' ); |
249 |
|
|
250 |
# |
# |
251 |
# fetch results |
# fetch results |
300 |
|
|
301 |
$times->{db} += time() - $t; |
$times->{db} += time() - $t; |
302 |
|
|
|
#$log->debug( "ds = " . Dumper( \@html_results ) ); |
|
|
|
|
303 |
$t = time(); |
$t = time(); |
304 |
|
|
305 |
my $html = $self->apply( |
my $html = $self->apply( |
322 |
|
|
323 |
} |
} |
324 |
|
|
|
#$log->debug( '@results = ' . Dumper( \@results ) ); |
|
|
|
|
325 |
$log->debug( sprintf( |
$log->debug( sprintf( |
326 |
"duration breakdown: estraier %.6fs, hash %.6fs, store %.6fs, apply %.6fs, decode %.06f, total: %.6fs", |
"duration breakdown: estraier %.6fs, hash %.6fs, store %.6fs, apply %.6fs, decode %.06f, total: %.6fs", |
327 |
$times->{est}, $times->{hash}, $times->{db}, $times->{apply}, $times->{decode}, time() - $search_start_t, |
$times->{est}, $times->{hash}, $times->{db}, $times->{apply}, $times->{decode}, time() - $search_start_t, |
347 |
|
|
348 |
my $args = {@_}; |
my $args = {@_}; |
349 |
my $log = $self->{log}; |
my $log = $self->{log}; |
350 |
$log->debug("record args: " . Dumper( $args )); |
$log->dumper( $args, 'args' ); |
351 |
|
|
352 |
foreach my $f (qw/record_uri template/) { |
foreach my $f (qw/record_uri template/) { |
353 |
$log->fatal("need $f") unless ($args->{$f}); |
$log->fatal("need $f") unless ($args->{$f}); |
381 |
} |
} |
382 |
|
|
383 |
|
|
384 |
|
=head2 list_nodes |
385 |
|
|
386 |
|
my @nodes = $m->list_nodes( 'site' ); |
387 |
|
|
388 |
|
Return all databases which have records for selected site. Returned array of |
389 |
|
hashes has elements C<name> and C<label>. |
390 |
|
|
391 |
|
=cut |
392 |
|
|
393 |
|
sub list_nodes { |
394 |
|
my $self = shift; |
395 |
|
|
396 |
|
my $site = shift; |
397 |
|
|
398 |
|
$self->{log}->debug("list_nodes use site $site"); |
399 |
|
|
400 |
|
$self->setup_site( $site ); |
401 |
|
|
402 |
|
my @nodes; |
403 |
|
|
404 |
|
if ($self->{est_node}->doc_num > 0) { |
405 |
|
push @nodes, { |
406 |
|
name => $self->{est_node}->name, |
407 |
|
label => $self->{est_node}->label, |
408 |
|
doc_num => $self->{est_node}->doc_num, |
409 |
|
} |
410 |
|
} |
411 |
|
|
412 |
|
# refresh set info |
413 |
|
$self->{est_node}->_set_info; |
414 |
|
|
415 |
|
my $links = $self->{est_node}->links || return @nodes; |
416 |
|
|
417 |
|
$self->{log}->dumper( $links, 'links' ); |
418 |
|
|
419 |
|
foreach my $link (@{ $links }) { |
420 |
|
my ($url, $label, $credit) = split(/\t/, $link, 3); |
421 |
|
if ($url =~ m#/node/(.+)$#) { |
422 |
|
my $node = $1; |
423 |
|
$self->setup_site( $node ); |
424 |
|
$self->{est_node}->_set_info; |
425 |
|
push @nodes, { |
426 |
|
name => $node, |
427 |
|
label => $label, |
428 |
|
doc_num => $self->{est_node}->doc_num, |
429 |
|
} |
430 |
|
} else { |
431 |
|
$self->{log}->warn("can't find node name in link $link"); |
432 |
|
} |
433 |
|
} |
434 |
|
|
435 |
|
$self->setup_site( $site ); |
436 |
|
$self->{est_node}->_set_info; |
437 |
|
|
438 |
|
$self->{log}->dumper( \@nodes, 'nodes' ); |
439 |
|
|
440 |
|
return @nodes; |
441 |
|
} |
442 |
|
|
443 |
|
=cut |
444 |
|
|
445 |
|
|
446 |
=head2 save_html |
=head2 save_html |
447 |
|
|
448 |
$m->save_html( '/full/path/to/file', $content ); |
$m->save_html( '/full/path/to/file', $content ); |