1 |
package Webpacus::Controller::Results; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use base qw/Catalyst::Controller/; |
6 |
use Data::Dumper; |
7 |
|
8 |
=head1 NAME |
9 |
|
10 |
Webpacus::Controller::Results - Display results from WebPAC |
11 |
|
12 |
=head1 SYNOPSIS |
13 |
|
14 |
See L<Webpacus> |
15 |
|
16 |
=head1 DESCRIPTION |
17 |
|
18 |
Catalyst Controller. |
19 |
|
20 |
=head1 METHODS |
21 |
|
22 |
=over 4 |
23 |
|
24 |
=item default |
25 |
|
26 |
=cut |
27 |
|
28 |
sub default : Private { |
29 |
my ( $self, $c ) = @_; |
30 |
|
31 |
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'; |
75 |
} |
76 |
|
77 |
=back |
78 |
|
79 |
|
80 |
=head1 AUTHOR |
81 |
|
82 |
Dobrica Pavlinusic,,, |
83 |
|
84 |
=head1 LICENSE |
85 |
|
86 |
This library is free software, you can redistribute it and/or modify |
87 |
it under the same terms as Perl itself. |
88 |
|
89 |
=cut |
90 |
|
91 |
1; |