6 |
use base qw/ |
use base qw/ |
7 |
Catalyst::Model |
Catalyst::Model |
8 |
/; |
/; |
|
use Data::Dumper; |
|
9 |
use WebPAC::Store 0.08; |
use WebPAC::Store 0.08; |
|
use WebPAC::Output::TT 0.07; |
|
10 |
use WebPAC::Search::Estraier 0.05; |
use WebPAC::Search::Estraier 0.05; |
11 |
use File::Slurp; |
use File::Slurp; |
12 |
use Time::HiRes; |
use Time::HiRes qw/time/; |
13 |
use Encode qw/encode decode from_to/; |
use Encode qw/encode decode from_to/; |
14 |
use Data::HTMLDumper; |
use Data::Dumper; |
15 |
|
|
16 |
=head1 NAME |
=head1 NAME |
17 |
|
|
92 |
database => $est_cfg->{database}, |
database => $est_cfg->{database}, |
93 |
); |
); |
94 |
|
|
|
$self->{out} = new WebPAC::Output::TT( |
|
|
include_path => $template_path, |
|
|
filters => { |
|
|
dump_html => sub { |
|
|
return unless (@_); |
|
|
my $out; |
|
|
my $i = 1; |
|
|
foreach my $v (@_) { |
|
|
$out .= qq{<div id="dump_$i">} . |
|
|
Data::HTMLDumper->Dump([ $v ],[ "v$i" ]) . |
|
|
qq{</div>}; |
|
|
$i++; |
|
|
} |
|
|
$out =~ s!<table[^>/]*>!<table class="dump">!gis if ($out); |
|
|
return $out; |
|
|
} |
|
|
}, |
|
|
); |
|
|
|
|
95 |
# default template from config.yaml |
# default template from config.yaml |
96 |
$self->{template} ||= $c->config->{webpac}->{template}; |
$self->{template} ||= $c->config->{webpac}->{template}; |
97 |
|
|
102 |
|
|
103 |
$self->{databases} = $c->config->{databases} || $log->error("can't find databases in config"); |
$self->{databases} = $c->config->{databases} || $log->error("can't find databases in config"); |
104 |
|
|
105 |
|
$self->{model_record} = $c->comp('Model::Record') or $log->error("can't find Model::Record"); |
106 |
|
|
107 |
return $self; |
return $self; |
108 |
|
|
109 |
} |
} |
129 |
sub search { |
sub search { |
130 |
my $self = shift; |
my $self = shift; |
131 |
|
|
132 |
|
my $search_start_t = time(); |
133 |
|
|
134 |
my $args = {@_}; |
my $args = {@_}; |
135 |
|
|
136 |
my $log = $self->{log}; |
my $log = $self->{log}; |
171 |
|
|
172 |
my $hits = $#results + 1; |
my $hits = $#results + 1; |
173 |
|
|
174 |
$log->debug( sprintf("search took %.2fs and returned $hits hits.", $times->{est}) ); |
$log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) ); |
175 |
|
|
176 |
# just return results? |
# just return results? |
177 |
return @results unless ($args->{'template'}); |
return @results unless ($args->{'template'}); |
208 |
|
|
209 |
$t = time(); |
$t = time(); |
210 |
|
|
211 |
my $html = $self->{out}->apply( |
my $html = '[no output]'; |
212 |
template => $template_filename, |
|
213 |
data => $ds, |
if ($self->{model_record}) { |
214 |
record_uri => "${database}/${prefix}/${id}", |
$html = $self->{model_record}->apply( |
215 |
config => $self->{databases}->{$database}, |
template => $template_filename, |
216 |
); |
data => $ds, |
217 |
|
record_uri => "${database}/${prefix}/${id}", |
218 |
|
config => $self->{databases}->{$database}, |
219 |
|
); |
220 |
|
} else { |
221 |
|
$log->warn("skipped apply"); |
222 |
|
} |
223 |
|
|
224 |
$times->{out} += time() - $t; |
$times->{out} += time() - $t; |
225 |
|
|
234 |
#$log->debug( '@html_results = ' . Dumper( \@html_results ) ); |
#$log->debug( '@html_results = ' . Dumper( \@html_results ) ); |
235 |
|
|
236 |
$log->debug( sprintf( |
$log->debug( sprintf( |
237 |
"time spent: db = %.2f, out = %.2f", |
"duration breakdown: store %.6fs, apply %.6fs, total: %.6fs", |
238 |
$times->{db}, $times->{out}, |
$times->{db}, $times->{out}, time() - $search_start_t, |
239 |
) ); |
) ); |
240 |
|
|
241 |
return \@html_results; |
return \@html_results; |
279 |
return; |
return; |
280 |
} |
} |
281 |
|
|
282 |
my $html = $self->{out}->apply( |
my $html = $self->{model_record}->apply( |
283 |
template => $args->{template}, |
template => $args->{template}, |
284 |
data => $ds, |
data => $ds, |
285 |
record_uri => $args->{record_uri}, |
record_uri => $args->{record_uri}, |