--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/22 12:57:09 92 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/12/05 19:15:11 224 @@ -3,9 +3,15 @@ use strict; use warnings; use lib '/data/webpac2/lib'; -use base qw/Catalyst::Model/; -use WebPAC::Search::Estraier; +use base qw/ + Catalyst::Model +/; use Data::Dumper; +use WebPAC::Store 0.03; +use WebPAC::Output::TT 0.02; +use WebPAC::Search::Estraier 0.05; +use File::Slurp; +use Time::HiRes; =head1 NAME @@ -28,9 +34,21 @@ # configuration for hyper estraier full text search engine hyperestraier: - url: 'http://localhost:1978/node/webpac2' - user: 'admin' - passwd: 'admin' + masterurl: 'http://localhost:1978/node/webpac2' + defaultnode: 'webpac2' + defaultdepth: 1 + 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 @@ -41,28 +59,284 @@ $self->config($config); my $log = $c->log; + $self->{log} = $log; -# if (! $c->stash->{est}) { + my $est_cfg = $c->config->{hyperestraier}; + $est_cfg->{'log'} = $log; - my $est_cfg = $c->config->{hyperestraier}; - $est_cfg->{'log'} = $log; + $est_cfg->{encoding} = $est_cfg->{catalyst_encoding}; - $log->debug("using config:" . Dumper($est_cfg) ); + $log->debug("using config:" . Dumper($est_cfg) ); -# $c->stash->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); -# } + if (! $est_cfg->{database}) { + my $defaultnode = $est_cfg->{defaultnode} || $log->logdie("can't find defaultnode in estraier configuration"); + $log->info("using default node $defaultnode"); + $est_cfg->{database} = $defaultnode; + } + + $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); + + # save config parametars in object + foreach my $f (qw/db_path template_path hits_on_page webpac_encoding out_encoding defaultdepth/) { + $self->{$f} = $c->config->{hyperestraier}->{$f} || + $c->config->{webpac}->{$f}; + $log->debug("self->{$f} = " . $self->{$f}); + } + my $db_path = $self->{db_path}; + my $template_path = $self->{template_path}; + + $log->debug("using db path '$db_path', template path '$template_path'"); + + $self->{db} = new WebPAC::Store( + path => $db_path, + read_only => 1, + database => $est_cfg->{database}, + ); + + $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} . + "'" + ); -# $log->debug("param: " . Dumper($c->req->params)); - -# $c->stash->{est}->search( -# query => $c->req->params->{Title}, -# max => 100, -# ); return $self; } + +=head2 search + + my $m->search( + phrase => 'query phrase', + add_attr => \@add_attr + get_attr => [ '@uri' ], + max => 42, + template => 'result_template.tt', + depth => 1, + ); + +All fields are standard C parametars except +C