--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/22 14:45:12 99 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/23 21:52:35 119 @@ -5,11 +5,11 @@ use lib '/data/webpac2/lib'; use base qw/ Catalyst::Model - WebPAC::Search::Estraier /; use Data::Dumper; use WebPAC::DB; use WebPAC::Output::TT; +use WebPAC::Search::Estraier 0.02; =head1 NAME @@ -78,6 +78,7 @@ filters => { foo => sub { shift } }, ); + # default template from config.yaml $self->{template} ||= $c->config->{webpac}->{template}; $self->{iconv} = new Text::Iconv( @@ -85,10 +86,10 @@ $c->config->{webpac}->{out_encoding} ); - $log->debug("converting encoding from webpac_encoding '" , - $c->config->{webpac}->{webpac_encoding}, - "' to '", - $c->config->{webpac}->{out_encoding}, + $log->debug("converting encoding from webpac_encoding '" . + $c->config->{webpac}->{webpac_encoding} . + "' to '" . + $c->config->{webpac}->{out_encoding} . "'" ); @@ -97,37 +98,49 @@ } sub search { - my ( $self, $query ) = @_; + my ( $self, $query, $template, $add_attr ) = @_; my $log = $self->{log}; - $log->debug("search model query: -->$query<--"); + $log->debug("search model query: '$query', add_attr: '" . join("','", @{$add_attr}) . "'"); - my $template_filename = $self->{template}; + my $template_filename = $template || $self->{template}; my @results = $self->{est}->search( - query => $query, - attr => [ '@uri' ], + phrase => $query, + get_attr => [ '@uri' ], max => 100, + add_attr => $add_attr, ); $log->debug("loading " . ($#results + 1) . " results"); + my @html_results; + for my $i ( 0 .. $#results ) { my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#); - # $log->debug("load_ds( $mfn )"); + #$log->debug("load_ds( $mfn )"); - my $ds = $self->{db}->load_ds( $mfn ) || next; - $results[$i]->{ html } = $self->{iconv}->convert( - $self->{out}->apply( + my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next; + + #$log->debug( "ds = " . Dumper( \@html_results ) ); + + my $html = $self->{out}->apply( template => $template_filename, data => $ds, - ) ); + ); + + $html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html"); + + push @html_results, $html; + } - return \@results; + #$log->debug( '@html_results = ' . Dumper( \@html_results ) ); + + return \@html_results; }