--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/30 23:21:30 200 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/12/14 23:11:06 248 @@ -7,9 +7,9 @@ Catalyst::Model /; use Data::Dumper; -use WebPAC::DB; -use WebPAC::Output::TT 0.02; -use WebPAC::Search::Estraier 0.02; +use WebPAC::Store 0.08; +use WebPAC::Output::TT 0.04; +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,10 +68,16 @@ $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 } ); # save config parametars in object - foreach my $f (qw/db_path template_path hits_on_page webpac_encoding out_encoding/) { + 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}); @@ -79,9 +87,10 @@ $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, + database => $est_cfg->{database}, ); $self->{out} = new WebPAC::Output::TT( @@ -118,6 +127,7 @@ get_attr => [ '@uri' ], max => 42, template => 'result_template.tt', + depth => 1, ); All fields are standard C parametars except @@ -156,6 +166,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; @@ -175,13 +192,23 @@ for my $i ( 0 .. $#results ) { - my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#); + my ($database, $prefix, $id); + if ( $results[$i]->{'@uri'} =~ m!/([^/]+)/([^/]+)#(\d+)$!) { + ($database, $prefix,$id) = ($1,$2,$3); + } else { + $log->warn("can't decode prefix#id from " . $results[$i]->{'@uri'}); + next; + } - #$log->debug("load_ds( $mfn )"); + #$log->debug("load_ds( id => $id, prefix => '$prefix' )"); $t = time(); - my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next; + my $ds = $self->{db}->load_ds( database => $database, prefix => $prefix, id => $id ); + if (! $ds) { + $log->error("can't load_ds( ${database}/${prefix}#${id} )"); + next; + } $times->{db} += time() - $t; @@ -192,6 +219,7 @@ my $html = $self->{out}->apply( template => $template_filename, data => $ds, + record_uri => "${database}/${prefix}/${id}", ); $times->{out} += time() - $t; @@ -235,17 +263,29 @@ my $log = $self->{log}; $log->debug("args: " . Dumper( $args )); - foreach my $f (qw/mfn template/) { - $log->die("need $f") unless ($args->{$f}); + foreach my $f (qw/record_uri template/) { + $log->fatal("need $f") unless ($args->{$f}); } - my $mfn = $args->{mfn}; + my ($database, $prefix, $id); - my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next; + if ($args->{record_uri} =~ m#^([^/]+)/([^/]+)/([^/]+)$#) { + ($database, $prefix, $id) = ($1,$2,$3); + } else { + $log->error("can't parse $args->{record_uri} into prefix, database and uri"); + return; + } + + my $ds = $self->{db}->load_ds( id => $id, prefix => $prefix, database => $database ); + if (! $ds) { + $log->error("can't load_ds( $database/$prefix/$id )"); + return; + } my $html = $self->{out}->apply( template => $args->{template}, data => $ds, + record_uri => $args->{record_uri}, ); $html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html");