/[webpac2]/Webpacus/lib/Webpacus/Controller/Search.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/Controller/Search.pm

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

revision 142 by dpavlin, Wed Nov 23 21:52:25 2005 UTC revision 143 by dpavlin, Fri Nov 25 01:24:31 2005 UTC
# Line 39  Returns results for URLs like C<search/s Line 39  Returns results for URLs like C<search/s
39  =cut  =cut
40    
41  sub suggest : Regex('^search/suggest/*([^/]*)') {  sub suggest : Regex('^search/suggest/*([^/]*)') {
42      my ( $self, $c ) = @_;          my ( $self, $c ) = @_;
43    
44      my $what = $c->request->snippets->[0];          my $what = $c->request->snippets->[0];
45    
46      my $log = $c->log;          my $log = $c->log;
47    
48   my $est = new WebPAC::Search::Estraier(          my $est_conf = $c->config->{hyperestraier};
49          url => 'http://localhost:1978/node/webpac2',          $est_conf->{log} = $c->log;
         user => 'admin',  
         passwd => 'admin',  
         encoding => 'UTF-8',  
         log => $c->log,  
  );  
       
50    
51      my $q = $c->req->params->{$what} ||          my $est = new WebPAC::Search::Estraier( %{ $est_conf } );
52          $c->req->params->{all} || $c->res->output("no results");  
53            my $q = $c->req->params->{$what} ||
54                    $c->req->params->{all} || $c->res->output("no results");
55    
     my @suggestions;  
56    
57          $log->info("search for '$q' in $what\n");          $log->info("search for '$q' in $what\n");
     my @hits = $est->search( phrase => $q, max => 10, get_attr => [ $what ] );  
58    
59      my $used;          my $max = $est_conf->{'hits_for_suggest'};
60            if (! $max) {
61                    $log->info("hits_for_suggest isn't defined, defaulting to 10");
62                    $c->config->{'hits_for_suggest'} = 10;
63                    $max = 10;
64            }
65    
66            my @hits = $est->search( phrase => $q, max => $max, get_attr => [ $what ] );
67    
68            my $used;
69            my @suggestions;
70    
71            foreach my $res (@hits) {
72                    my $v = $res->{ $what } || next;
73                    next if ($used->{ $v }++);
74                    push @suggestions, $v;
75            }
76    
77      foreach my $res (@hits) {          $log->debug( ($#suggestions + 1) . " unique hits returned");
         my $v = $res->{ $what } || next;  
         next if ($used->{ $v }++);  
         push @suggestions, $v;  
     }  
78    
79      $c->res->body( $c->prototype->auto_complete_result( \@suggestions ) );          $c->res->body( $c->prototype->auto_complete_result( \@suggestions ) );
80  }  }
81    
82  =back  =back

Legend:
Removed from v.142  
changed lines
  Added in v.143

  ViewVC Help
Powered by ViewVC 1.1.26