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

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

revision 129 by dpavlin, Thu Nov 24 12:17:55 2005 UTC revision 147 by dpavlin, Fri Nov 25 18:52:28 2005 UTC
# Line 3  package Webpacus::Controller::Results; Line 3  package Webpacus::Controller::Results;
3  use strict;  use strict;
4  use warnings;  use warnings;
5  use base qw/Catalyst::Controller/;  use base qw/Catalyst::Controller/;
6    use Data::Dumper;
7    
8    my $hest_op_regex = qr/\[(:?BW|EW|RX)\]/;
9    
10  =head1 NAME  =head1 NAME
11    
# Line 25  Catalyst Controller. Line 28  Catalyst Controller.
28  =cut  =cut
29    
30  sub default : Private {  sub default : Private {
31      my ( $self, $c ) = @_;          my ( $self, $c ) = @_;
   
     my $webpac = $c->comp('Model::WebPAC');  
     my $params = $c->req->params;  
     my $log = $c->log;  
   
 use Data::Dumper;  
     $log->debug("results got params: " . Dumper( $params ) );  
   
     my $q;  
     my @attr;  
32    
33      foreach my $f (keys %{ $params }) {          my $webpac = $c->comp('Model::WebPAC');
34            my $params = $c->req->params;
35          next if ($f =~ m/^_/o);          my $log = $c->log;
36    
37          my $v = $params->{$f} || next;          $log->debug("results got params: " . Dumper( $params ) );
38    
39          $q .= "$v ";          my @attr;
40            my @words;
41          next if ($f eq 'all');  # don't add_attr for magic field all          # default operator to join fields/words
42            my $operator = 'AND';
43          if ($v !~ /\s/) {  
44                  push @attr, "$f ISTRINC $v";          foreach my $f (keys %{ $params }) {
45          } else {  
46                  map { push @attr, "$f ISTRINC $_"; } split(/\s+/, $v);                  next if ($f =~ m/^_/o);
47    
48                    my $v = $params->{$f} || next;
49    
50                    if (my $op = $params->{ '_' . $f}) {
51                            if ($v =~ $hest_op_regex) {
52                                    # don't split words if there is Hyper Estraier
53                                    # operator in them
54                                    push @words, $v;
55                            } else {
56                                    push @words, join(" $op ", split(/\s+/, $v) );
57                            }
58                    } else {
59                            push @words, $v;
60                    }
61    
62                    next if ($f eq 'all');  # don't add_attr for magic field all
63    
64                    if ($v !~ /\s/) {
65                            push @attr, "$f ISTRINC $v";
66                    } else {
67                            map {
68                                    push @attr, "$f ISTRINC $_";
69                            } grep { ! $hest_op_regex } split(/\s+/, $v);
70                    }
71          }          }
     }  
72    
73      # strip spaces from beginning and end          my $q = join(" $operator ", @words);
74      $q =~ s/^\s+//;  
75      $q =~ s/\s+$//;          my $template = $params->{'_template'};
76            $log->debug("using template $template");
77    
78      $c->stash->{html_results} = sub {          $c->stash->{html_results} = sub {
79          my $res = $webpac->search( $q, $params->{'_template'}, \@attr );                  my $res = $webpac->search( $q, $template, \@attr );
80  #       $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res ));          #       $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res ));
81          return $res;                  return $res;
82      };          };
83    
84      $c->stash->{phrase} = $q;          $c->stash->{phrase} = $q;
85            $c->stash->{attr} = \@attr;
86    
87      $c->stash->{template} = 'results.tt';          $c->stash->{template} = 'results.tt';
88  }  }
89    
90  =back  =back

Legend:
Removed from v.129  
changed lines
  Added in v.147

  ViewVC Help
Powered by ViewVC 1.1.26