--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/26 20:21:54 165 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/12/05 19:15:01 222 @@ -7,9 +7,9 @@ Catalyst::Model /; use Data::Dumper; -use WebPAC::DB; -use WebPAC::Output::TT; -use WebPAC::Search::Estraier 0.02; +use WebPAC::Store 0.03; +use WebPAC::Output::TT 0.02; +use WebPAC::Search::Estraier 0.05; use File::Slurp; use Time::HiRes; @@ -34,7 +34,9 @@ # configuration for hyper estraier full text search engine hyperestraier: - url: 'http://localhost:1978/node/webpac2' + masterurl: 'http://localhost:1978/node/webpac2' + defaultnode: 'webpac2' + defaultdepth: 1 user: 'admin' passwd: 'admin' hits_on_page: 100 @@ -66,15 +68,26 @@ $log->debug("using config:" . Dumper($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 } ); - my $db_path = $c->config->{webpac}->{db_path}; - my $template_path = $c->config->{webpac}->{template_path}; - $self->{template_path} = $template_path; + # 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::DB( + $self->{db} = new WebPAC::Store( path => $db_path, read_only => 1, ); @@ -99,35 +112,11 @@ "'" ); - # save config parametars in object - foreach my $f (qw/hits_on_page/) { - $self->{$f} = $c->config->{hyperestraier}->{$f}; - $log->debug("self->{$f} = " . $self->{$f}); - } return $self; } -=head2 iconv_on_save - - my $out = $m->iconv_on_save( $content ); - -Convert data saved to disk in Webpac encoding. - -=cut - -sub iconv_on_save { - my $self = shift; - - $self->{iconv_save} ||= new Text::Iconv( - $self->config->{webpac}->{out_encoding}, - $self->config->{webpac}->{webpac_encoding}, - ); - - $self->{iconv_save}->convert( @_ ); -} - =head2 search @@ -137,6 +126,7 @@ get_attr => [ '@uri' ], max => 42, template => 'result_template.tt', + depth => 1, ); All fields are standard C parametars except @@ -175,6 +165,13 @@ my $t = time(); + # transfer depth of search + if (! $args->{depth}) { + my $default = $self->{defaultdepth} || $log->logdie("can't find defaultdepth in estraier configuration"); + $args->{depth} = $default; + $log->warn("using default search depth $default"); + } + my @results = $self->{est}->search( %{ $args } ); $times->{est} += time() - $t; @@ -276,7 +273,7 @@ $m->save_html( '/full/path/to/file', $content ); -It will use C to convert content encoding back to +It will use C to convert content encoding back to Webpac codepage, recode JavaScript Unicode entities (%u1234), strip extra newlines at beginning and end, and save to C and if that succeeds, just rename @@ -287,8 +284,6 @@ sub save_html { my ($self, $path, $content) = @_; - $content = $self->iconv_on_save( $content ) || die "no content?"; - sub _conv_js { my $t = shift || return; return $self->{iconv}->convert(chr(hex($t))); @@ -297,7 +292,19 @@ $content =~ s/^[\n\r]+//s; $content =~ s/[\n\r]+$/\n/s; - write_file($path . '.new', $content) || die "can't save ${path}.new $!"; + my ($from, $to) = ( + $self->{out_encoding}, + $self->{webpac_encoding}, + ); + + $self->{log}->debug("using iconv to convert from $from to $to encoding"); + + my $iconv_on_save = new Text::Iconv($from, $to) + || $self->{log}->fatal("can't create iconv for saving"); + + $content = $iconv_on_save->convert( $content ) || die "no content?"; + + write_file($path . '.new', {binmode => ':raw' }, $content) || die "can't save ${path}.new $!"; rename $path . '.new', $path || die "can't rename to $path: $!"; } @@ -316,7 +323,7 @@ die "no path?" unless ($path); - my $content = read_file($path) || die "can't read $path: $!"; + my $content = read_file($path, {binmode => ':raw' }) || die "can't read $path: $!"; #$content = $q->escapeHTML($iconv_utf8->convert($content)); $content = $self->{iconv}->convert($content);