--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/22 12:57:20 94 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/26 01:54:42 155 @@ -5,9 +5,13 @@ 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; +use File::Slurp; +use Time::HiRes; =head1 NAME @@ -30,9 +34,19 @@ # 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' + hits_on_page: 100 + + 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 @@ -48,30 +62,229 @@ my $est_cfg = $c->config->{hyperestraier}; $est_cfg->{'log'} = $log; + $est_cfg->{encoding} = $est_cfg->{catalyst_encoding}; + $log->debug("using config:" . Dumper($est_cfg) ); $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); + my $db_path = $c->config->{webpac}->{db_path}; + my $template_path = $c->config->{webpac}->{template_path}; + $self->{template_path} = $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} . + "'" + ); + + # save config parametars in object + foreach my $f (qw/hits_on_page/) { + $self->{$_} = $c->config->{$_}; + $log->debug("self->{$_} = " . $c->config->{$_}); + } + return $self; } -sub search { - my ( $self, $query ) = @_; +=head2 iconv_on_save + + my $out = $m->iconv_on_save( $content ); - $self->{log}->debug("search got query: $query<--"); +Convert data saved to disk in Webpac encoding. + +=cut - my @results = $self->{est}->search( - query => $query, - attr => [ '@uri' ], - max => 100, +sub iconv_on_save { + my $self = shift; + + $self->{iconv_save} ||= new Text::Iconv( + $self->config->{webpac}->{out_encoding}, + $self->config->{webpac}->{webpac_encoding}, ); - return @results; + $self->{iconv_save}->convert( @_ ); +} + + +=head2 search + + my $m->search( + phrase => 'query phrase', + add_attr => \@add_attr + get_attr => [ '@uri' ], + max => 42, + template => 'result_template.tt', + ); + +All fields are standard C parametars except +C