--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/22 12:57:15 93 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/23 00:15:01 115 @@ -8,6 +8,8 @@ WebPAC::Search::Estraier /; use Data::Dumper; +use WebPAC::DB; +use WebPAC::Output::TT; =head1 NAME @@ -30,9 +32,18 @@ # configuration for hyper estraier full text search engine hyperestraier: - url: 'http://localhost:1978/node/webpac2' - user: 'admin' - passwd: 'admin' + url: 'http://localhost:1978/node/webpac2' + user: 'admin' + passwd: 'admin' + + webpac: + db_path: '/data/webpac2/db' + template_path: '/data/webpac2/conf/output/tt' + template: 'html_ffzg_results_short.tt' + # encoding comming from webpac + webpac_encoding: 'iso-8859-2' + # encoding expected by Catalyst + out_encoding: 'UTF-8' =cut @@ -43,6 +54,7 @@ $self->config($config); my $log = $c->log; + $self->{log} = $log; my $est_cfg = $c->config->{hyperestraier}; $est_cfg->{'log'} = $log; @@ -51,17 +63,48 @@ $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); -# $c->stash->{est}->search( -# query => $c->req->params->{Title}, -# max => 100, -# ); + my $db_path = $c->config->{webpac}->{db_path}; + my $template_path = $c->config->{webpac}->{template_path}; + + $log->debug("using db path '$db_path', template path '$template_path'"); + + $self->{db} = new WebPAC::DB( + path => $db_path, + read_only => 1, + ); + + $self->{out} = new WebPAC::Output::TT( + include_path => $template_path, + filters => { foo => sub { shift } }, + ); + + # default template from config.yaml + $self->{template} ||= $c->config->{webpac}->{template}; + + $self->{iconv} = new Text::Iconv( + $c->config->{webpac}->{webpac_encoding}, + $c->config->{webpac}->{out_encoding} + ); + + $log->debug("converting encoding from webpac_encoding '" . + $c->config->{webpac}->{webpac_encoding} . + "' to '" . + $c->config->{webpac}->{out_encoding} . + "'" + ); return $self; } sub search { - my ( $self, $query ) = @_; + my ( $self, $query, $template ) = @_; + + my $log = $self->{log}; + + $log->debug("search model query: -->$query<--"); + + my $template_filename = $template || $self->{template}; my @results = $self->{est}->search( query => $query, @@ -69,7 +112,34 @@ max => 100, ); - return \@results; + $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 )"); + + 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; + + } + + #$log->debug( '@html_results = ' . Dumper( \@html_results ) ); + + return \@html_results; }