/[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 420 by dpavlin, Sun Mar 12 21:50:26 2006 UTC revision 451 by dpavlin, Sun May 7 19:58:43 2006 UTC
# Line 153  sub setup_site { Line 153  sub setup_site {
153          my $self = shift;          my $self = shift;
154    
155          my $site = shift || $self->{defaultnode};          my $site = shift || $self->{defaultnode};
156            if (! $site) {
157                    $self->{log}->warn("not changing site from " . $self->{est_node}->{url});
158                    return;
159            }
160    
161          $self->{log}->fatal("setup_site can't find site or defaultnode") unless ($site);          $self->{log}->fatal("setup_site can't find site or defaultnode") unless ($site);
162    
163          my $url = $self->{masterurl} . '/node/' . $site;          my $url = $self->{masterurl} . '/node/' . $site;
164          $self->{est_node}->set_url( $url );          $self->{est_node}->set_url( $url );
165          $self->{log}->debug("setup_site $site using $url");          $self->{log}->debug("setup_site '$site' using $url");
166  }  }
167    
168  =head2 search  =head2 search
# Line 193  sub search { Line 197  sub search {
197    
198          my $template_filename = $args->{template} || $self->{template};          my $template_filename = $args->{template} || $self->{template};
199    
200          $args->{max} ||= $self->{'hits_for_pager'};          $args->{hits_on_page} ||= $self->{'hits_for_pager'};
201          if (! $args->{max}) {          if (! $args->{hits_on_page}) {
202                  $args->{max} = 100;                  $args->{hits_on_page} = 100;
203                  $log->warn("max not set when calling model. Using default of $args->{max}");                  $log->warn("max not set when calling model. Using default of $args->{hits_on_page}");
204          }          }
205    
206          my $times;      # store some times for benchmarking          my $times;      # store some times for benchmarking
# Line 211  sub search { Line 215  sub search {
215          }          }
216          $args->{depth} ||= 0;          $args->{depth} ||= 0;
217    
218          $log->debug("searching for maximum $args->{max} results using depth $args->{depth} phrase: ", $query || '[none]');          $log->debug("searching " . $self->{est_node}->{url} . " hits on page: $args->{hits_on_page} depth: $args->{depth} phrase: " . ($query || '[none]') );
219    
220          #          #
221          # construct condition for Hyper Estraier          # construct condition for Hyper Estraier
# Line 229  sub search { Line 233  sub search {
233          $cond->set_options( $args->{options} ) if ($args->{options});          $cond->set_options( $args->{options} ) if ($args->{options});
234          $cond->set_order( $args->{order} ) if ($args->{order});          $cond->set_order( $args->{order} ) if ($args->{order});
235    
236          my $max = $args->{max} || 7;          my $hits_on_page = $args->{hits_on_page} || 7;
237          my $page = $args->{page} || 1;          my $page = $args->{page} || 1;
238          if ($page < 1) {          if ($page < 1) {
239                  $log->warn("page number $page < 1");                  $log->warn("page number $page < 1");
240                  $page = 1;                  $page = 1;
241          }          }
242    
243          $cond->set_max( $page * $max );          $cond->set_max( my $max = $page * $hits_on_page );
244            $cond->set_skip( my $skip = ( $page - 1 ) * $hits_on_page );
245    
246            $log->debug("search max: $max, skip: $skip");
247    
248          my $result = $self->{est_node}->search($cond, $args->{depth});          my $result = $self->{est_node}->search($cond, $args->{depth});
249          if (! $result) {          if (! $result) {
# Line 250  sub search { Line 257  sub search {
257          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );
258    
259          $self->{hints} = $result->{hints};          $self->{hints} = $result->{hints};
260          $log->dumper($self->{hints}, 'original hints' );          #$log->dumper($self->{hints}, 'original hints' );
261    
262          #          #
263          # fetch results          # fetch results
# Line 258  sub search { Line 265  sub search {
265    
266          my @results;          my @results;
267    
268          for my $i ( (($page - 1) * $max) .. ( $hits - 1 ) ) {          #for my $i ( (($page - 1) * $max) .. ( $hits - 1 ) ) {
269            for my $i ( 0 .. $max ) {
270    
271                  $t = time();                  $t = time();
272    
# Line 355  sub hints { Line 363  sub hints {
363    
364          while (my ($key,$val) = each %{ $self->{hints} }) {          while (my ($key,$val) = each %{ $self->{hints} }) {
365    
366                    #$self->{log}->debug("current hint $key = $val");
367    
368                  if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) {                  if ($key =~ m/^(?:HITS*|TIME|DOCNUM|WORDNUM)$/) {
369                          $hints->{ lc($key) } = $val;                          $hints->{ lc($key) } = $val;
370                  } elsif ($key =~ m/^HINT#/) {                  } elsif ($key =~ m/^HINT#/) {
# Line 364  sub hints { Line 374  sub hints {
374                          my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7);                          my ($url,undef,undef,undef,undef,undef,$results) = split(/\t/,$val,7);
375                          if ($url =~ m#/node/(.+)$#) {                          if ($url =~ m#/node/(.+)$#) {
376                                  $hints->{node}->{$1} = $results;                                  $hints->{node}->{$1} = $results;
377                            } else {
378                                    $self->{log}->debug("url $url doesn't have /node/ in it!");
379                          }                          }
380                    } else {
381                            $self->{log}->debug("unknown hint $key = $val");
382                  }                  }
383    
384          }          }
385    
386          $self->{log}->dumper($hints, 'model hints' );          $self->{log}->dumper($hints, 'model hints' );
# Line 432  sub record { Line 447  sub record {
447  Return all databases which have records for selected site. Returned array of  Return all databases which have records for selected site. Returned array of
448  hashes has elements C<name> and C<label>.  hashes has elements C<name> and C<label>.
449    
450    This function does cacheing inside C<< $self->{nodes_in_site} >>, but you
451    probably didn't want to know that.
452    
453  =cut  =cut
454    
455  sub list_nodes {  sub list_nodes {
456          my $self = shift;          my $self = shift;
457    
458          my $site = shift;          my $site = shift || $self->{defaultnode};
459    
460            # cache?
461            if ($self->{nodes_in_site}->{$site} && ref($self->{nodes_in_site}->{$site}) eq 'ARRAY') {
462                    $self->{log}->debug("list_nodes for site $site and returns from cache");
463                    return @{ $self->{nodes_in_site}->{$site} };
464            };
465    
466          $self->{log}->debug("list_nodes use site $site");          $self->{log}->debug("list_nodes for site $site");
467    
468          $self->setup_site( $site );          $self->setup_site( $site );
469    
# Line 480  sub list_nodes { Line 504  sub list_nodes {
504          $self->setup_site( $site );          $self->setup_site( $site );
505          $self->{est_node}->_set_info;          $self->{est_node}->_set_info;
506    
507          $self->{log}->dumper( \@nodes, 'nodes' );          $self->{nodes_in_site}->{$site} = \@nodes;
508    
509          return @nodes;          return @nodes;
510  }  }

Legend:
Removed from v.420  
changed lines
  Added in v.451

  ViewVC Help
Powered by ViewVC 1.1.26