5 |
use lib '/data/webpac2/lib'; |
use lib '/data/webpac2/lib'; |
6 |
use base qw/ |
use base qw/ |
7 |
Catalyst::Model |
Catalyst::Model |
|
WebPAC::Search::Estraier |
|
8 |
/; |
/; |
9 |
use Data::Dumper; |
use Data::Dumper; |
10 |
use WebPAC::DB; |
use WebPAC::DB; |
11 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
12 |
|
use WebPAC::Search::Estraier 0.02; |
13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
15 |
|
|
78 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
79 |
); |
); |
80 |
|
|
81 |
|
# default template from config.yaml |
82 |
$self->{template} ||= $c->config->{webpac}->{template}; |
$self->{template} ||= $c->config->{webpac}->{template}; |
83 |
|
|
84 |
$self->{iconv} = new Text::Iconv( |
$self->{iconv} = new Text::Iconv( |
86 |
$c->config->{webpac}->{out_encoding} |
$c->config->{webpac}->{out_encoding} |
87 |
); |
); |
88 |
|
|
89 |
$log->debug("converting encoding from webpac_encoding '" , |
$log->debug("converting encoding from webpac_encoding '" . |
90 |
$c->config->{webpac}->{webpac_encoding}, |
$c->config->{webpac}->{webpac_encoding} . |
91 |
"' to '", |
"' to '" . |
92 |
$c->config->{webpac}->{out_encoding}, |
$c->config->{webpac}->{out_encoding} . |
93 |
"'" |
"'" |
94 |
); |
); |
95 |
|
|
98 |
} |
} |
99 |
|
|
100 |
sub search { |
sub search { |
101 |
my ( $self, $query ) = @_; |
my ( $self, $query, $template, @add_attr ) = @_; |
102 |
|
|
103 |
my $log = $self->{log}; |
my $log = $self->{log}; |
104 |
|
|
105 |
$log->debug("search model query: -->$query<--"); |
$log->debug("search model query: '$query', add_attr: '" . join("','", @add_attr) . "'"); |
106 |
|
|
107 |
my $template_filename = $self->{template}; |
my $template_filename = $template || $self->{template}; |
108 |
|
|
109 |
my @results = $self->{est}->search( |
my @results = $self->{est}->search( |
110 |
query => $query, |
phrase => $query, |
111 |
attr => [ '@uri' ], |
get_attr => [ '@uri' ], |
112 |
max => 100, |
max => 100, |
113 |
|
add_attr => @add_attr, |
114 |
); |
); |
115 |
|
|
116 |
$log->debug("loading " . ($#results + 1) . " results"); |
$log->debug("loading " . ($#results + 1) . " results"); |
117 |
|
|
118 |
|
my @html_results; |
119 |
|
|
120 |
for my $i ( 0 .. $#results ) { |
for my $i ( 0 .. $#results ) { |
121 |
|
|
122 |
my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#); |
my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#); |
123 |
|
|
124 |
# $log->debug("load_ds( $mfn )"); |
#$log->debug("load_ds( $mfn )"); |
125 |
|
|
126 |
my $ds = $self->{db}->load_ds( $mfn ) || next; |
my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next; |
127 |
$results[$i]->{ html } = $self->{iconv}->convert( |
|
128 |
$self->{out}->apply( |
#$log->debug( "ds = " . Dumper( \@html_results ) ); |
129 |
|
|
130 |
|
my $html = $self->{out}->apply( |
131 |
template => $template_filename, |
template => $template_filename, |
132 |
data => $ds, |
data => $ds, |
133 |
) ); |
); |
134 |
|
|
135 |
|
$html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html"); |
136 |
|
|
137 |
|
push @html_results, $html; |
138 |
|
|
139 |
} |
} |
140 |
|
|
141 |
return \@results; |
#$log->debug( '@html_results = ' . Dumper( \@html_results ) ); |
142 |
|
|
143 |
|
return \@html_results; |
144 |
} |
} |
145 |
|
|
146 |
|
|