/[webpac2]/Webpacus/lib/Webpacus/Model/WebPAC.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/lib/Webpacus/Model/WebPAC.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 382 by dpavlin, Sun Jan 22 02:52:24 2006 UTC revision 399 by dpavlin, Sun Feb 19 12:37:27 2006 UTC
# Line 87  sub new { Line 87  sub new {
87          $log->fatal("can't create Search::Estraier::Node $url") unless ($self->{est_node});          $log->fatal("can't create Search::Estraier::Node $url") unless ($self->{est_node});
88    
89          # save config parametars in object          # save config parametars in object
90          foreach my $f (qw/db_path template_path hits_on_page webpac_encoding defaultdepth/) {          foreach my $f (qw/
91                    db_path template_path hits_on_page webpac_encoding defaultdepth
92                    masterurl
93                    /) {
94                  $self->{$f} = $c->config->{hyperestraier}->{$f} ||                  $self->{$f} = $c->config->{hyperestraier}->{$f} ||
95                          $c->config->{webpac}->{$f};                          $c->config->{webpac}->{$f};
96                  $log->debug("self->{$f} = " . $self->{$f});                  $log->debug("self->{$f} = " . $self->{$f});
# Line 138  sub new { Line 141  sub new {
141    
142  }  }
143    
144    =head2 setup_site
145    
146     $self->setup_site('site_name');
147    
148    Change node URL and database name according to site name (if available)
149    
150    =cut
151    
152    sub setup_site {
153            my $self = shift;
154    
155            my $site = shift || return;
156    
157            my $url = $self->{masterurl} . '/node/' . $site;
158            $self->{est_node}->set_url( $url );
159            $self->{log}->debug("setup_site $site");
160    }
161    
162  =head2 search  =head2 search
163    
# Line 169  sub search { Line 189  sub search {
189    
190          my $query = $args->{phrase} || $log->warn("no query phrase") && return;          my $query = $args->{phrase} || $log->warn("no query phrase") && return;
191    
         $log->debug("search model query: '$query'");  
         if ($args->{add_attr}) {  
                 $log->debug(" + add_attr: " .  
                         join("','", @{ $args->{add_attr} })  
                 );  
         }  
   
192          my $template_filename = $args->{template} || $self->{template};          my $template_filename = $args->{template} || $self->{template};
193    
194          $args->{max} ||= $self->{'hits_for_pager'};          $args->{max} ||= $self->{'hits_for_pager'};
# Line 194  sub search { Line 207  sub search {
207                  $args->{depth} = $default;                  $args->{depth} = $default;
208                  $log->warn("using default search depth $default");                  $log->warn("using default search depth $default");
209          }          }
210            $args->{depth} ||= 0;
211    
212          $log->debug("searching for maximum $args->{max} results using depth $args->{depth}");          $log->debug("searching for maximum $args->{max} results using depth $args->{depth} phrase: ", $query || '[none]');
213    
214          #          #
215          # construct condition for Hyper Estraier          # construct condition for Hyper Estraier
# Line 204  sub search { Line 218  sub search {
218          if ( ref($args->{add_attr}) eq 'ARRAY' ) {          if ( ref($args->{add_attr}) eq 'ARRAY' ) {
219                  $log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) );                  $log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) );
220                  map {                  map {
221                          $cond->add_attr( _convert( $_ ) );                          $cond->add_attr( $_ );
222                          $log->debug(" + $_");                          $log->debug(" + $_");
223                  } @{ $args->{add_attr} };                  } @{ $args->{add_attr} };
224          };          };
# Line 220  sub search { Line 234  sub search {
234                  $page = 1;                  $page = 1;
235          }          }
236    
         $times->{est} += time() - $t;  
   
237          $cond->set_max( $page * $max );          $cond->set_max( $page * $max );
238    
239          my $result = $self->{est_node}->search($cond, ( $args->{depth} || 0 ));          my $result = $self->{est_node}->search($cond, $args->{depth});
240          my $hits = $result->doc_num;          my $hits = $result->doc_num;
241    
242            $times->{est} += time() - $t;
243    
244          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );
245    
246            $log->debug( "hints: " . Dumper($result->{hints}) );
247    
248          #          #
249          # fetch results          # fetch results
250          #          #
# Line 306  sub search { Line 322  sub search {
322    
323          }          }
324    
325          $log->debug( '@results = ' . Dumper( \@results ) );          #$log->debug( '@results = ' . Dumper( \@results ) );
326    
327          $log->debug( sprintf(          $log->debug( sprintf(
328                  "duration breakdown: estraier %.6fs, hash %.6fs, store %.6fs, apply %.6fs, decode %.06f, total: %.6fs",                  "duration breakdown: estraier %.6fs, hash %.6fs, store %.6fs, apply %.6fs, decode %.06f, total: %.6fs",
# Line 555  filter to return links to search, usage Line 571  filter to return links to search, usage
571    
572                                          my $s;                                          my $s;
573                                          if ($s_el > 0) {                                          if ($s_el > 0) {
574                                                  $s = $item->{'search'}->[$i] || die "can't find value $i for type search in field $search";                                                  $s = $item->{'search'}->[$i] or warn "can't find value $i for type search in field $search";
575                                          } else {                                          } else {
576                                                  $s = $item->{'search'}->[0];                                                  $s = $item->{'search'}->[0];
577                                          }                                          }
578                                          #$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;                                          #$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
579                                          $s = __quotemeta( $s );                                          $s = __quotemeta( $s );
580    
581                                          my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";                                          my $d = $item->{'display'}->[$i] or warn "can't find value $i for type display in field $display";
582    
583                                          my $template_arg = '';                                          my $template_arg = '';
584                                          $template_arg = qq{,'$template'} if ($template);                                          $template_arg = qq{,'$template'} if ($template);

Legend:
Removed from v.382  
changed lines
  Added in v.399

  ViewVC Help
Powered by ViewVC 1.1.26