2 |
|
|
3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use base 'Catalyst::Controller'; |
use base qw/Catalyst::Controller/; |
6 |
|
use Data::Dumper; |
7 |
|
|
8 |
=head1 NAME |
=head1 NAME |
9 |
|
|
10 |
Webpacus::Controller::Results - Catalyst Controller |
Webpacus::Controller::Results - Display results from WebPAC |
11 |
|
|
12 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
13 |
|
|
28 |
sub default : Private { |
sub default : Private { |
29 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
30 |
|
|
31 |
sleep 3; |
my $webpac = $c->comp('Model::WebPAC'); |
32 |
|
my $params = $c->req->params; |
33 |
|
my $log = $c->log; |
34 |
|
|
35 |
|
$log->debug("results got params: " . Dumper( $params ) ); |
36 |
|
|
37 |
|
my @attr; |
38 |
|
my @words; |
39 |
|
# default operator to join fields/words |
40 |
|
my $operator = 'AND'; |
41 |
|
|
42 |
|
foreach my $f (keys %{ $params }) { |
43 |
|
|
44 |
|
next if ($f =~ m/^_/o); |
45 |
|
|
46 |
|
my $v = $params->{$f} || next; |
47 |
|
|
48 |
|
if (my $op = $params->{ '_' . $f}) { |
49 |
|
push @words, join(" $op ", split(/\s+/, $v) ); |
50 |
|
} else { |
51 |
|
push @words, $v; |
52 |
|
} |
53 |
|
|
54 |
|
next if ($f eq 'all'); # don't add_attr for magic field all |
55 |
|
|
56 |
|
if ($v !~ /\s/) { |
57 |
|
push @attr, "$f ISTRINC $v"; |
58 |
|
} else { |
59 |
|
map { push @attr, "$f ISTRINC $_"; } split(/\s+/, $v); |
60 |
|
} |
61 |
|
} |
62 |
|
|
63 |
|
my $q = join(" $operator ", @words); |
64 |
|
|
65 |
|
$c->stash->{html_results} = sub { |
66 |
|
my $res = $webpac->search( $q, $params->{'_template'}, \@attr ); |
67 |
|
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
68 |
|
return $res; |
69 |
|
}; |
70 |
|
|
71 |
|
$c->stash->{phrase} = $q; |
72 |
|
$c->stash->{attr} = \@attr; |
73 |
|
|
74 |
$c->stash->{template} = 'results.tt'; |
$c->stash->{template} = 'results.tt'; |
75 |
} |
} |