4 |
use warnings; |
use warnings; |
5 |
use base 'Catalyst::Controller'; |
use base 'Catalyst::Controller'; |
6 |
|
|
7 |
|
use Data::Dumper; |
8 |
|
|
9 |
use lib '/data/webpac2/lib'; |
use lib '/data/webpac2/lib'; |
10 |
use WebPAC::Search::Estraier; |
use WebPAC::Search::Estraier; |
11 |
|
|
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
14 |
|
|
15 |
Webpacus::Controller::Search - Catalyst Controller |
Webpacus::Controller::Search - Catalyst Controller |
82 |
$c->res->body( $c->prototype->auto_complete_result( \@suggestions ) ); |
$c->res->body( $c->prototype->auto_complete_result( \@suggestions ) ); |
83 |
} |
} |
84 |
|
|
85 |
|
|
86 |
|
# specify all Hyper Estraier operators which should stop this module |
87 |
|
# from splitting search query and joining it with default operator |
88 |
|
my $hest_op_regex = qr/(:?\[(:?BW|EW|RX)\]|AND|OR|ANDNOT)/; |
89 |
|
|
90 |
|
=item results |
91 |
|
|
92 |
|
Mothod which uses C<Model::WebPAC> and returns results for search query |
93 |
|
|
94 |
|
=cut |
95 |
|
|
96 |
|
sub results : Local { |
97 |
|
my ( $self, $c ) = @_; |
98 |
|
|
99 |
|
my $webpac = $c->comp('Model::WebPAC'); |
100 |
|
my $params = $c->req->params; |
101 |
|
my $log = $c->log; |
102 |
|
|
103 |
|
$log->debug("results got params: " . Dumper( $params ) ); |
104 |
|
|
105 |
|
my @attr; |
106 |
|
my @words; |
107 |
|
# default operator to join fields/words |
108 |
|
my $operator = 'AND'; |
109 |
|
|
110 |
|
foreach my $f (keys %{ $params }) { |
111 |
|
|
112 |
|
next if ($f =~ m/^_/o); |
113 |
|
|
114 |
|
my $v = $params->{$f} || next; |
115 |
|
|
116 |
|
if (my $op = $params->{ '_' . $f}) { |
117 |
|
if ($v =~ $hest_op_regex) { |
118 |
|
# don't split words if there is Hyper Estraier |
119 |
|
# operator in them |
120 |
|
push @words, $v; |
121 |
|
} else { |
122 |
|
push @words, join(" $op ", split(/\s+/, $v) ); |
123 |
|
} |
124 |
|
} else { |
125 |
|
push @words, $v; |
126 |
|
} |
127 |
|
|
128 |
|
next if ($f eq 'all'); # don't add_attr for magic field all |
129 |
|
|
130 |
|
if ($v !~ /\s/) { |
131 |
|
push @attr, "$f ISTRINC $v"; |
132 |
|
} else { |
133 |
|
map { |
134 |
|
push @attr, "$f ISTRINC $_"; |
135 |
|
} grep { ! $hest_op_regex } split(/\s+/, $v); |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
|
my $q = join(" $operator ", @words); |
140 |
|
|
141 |
|
my $template = $params->{'_template'}; |
142 |
|
$log->debug("using template $template"); |
143 |
|
|
144 |
|
$c->stash->{html_results} = sub { |
145 |
|
my $res = $webpac->search( |
146 |
|
phrase => $q, |
147 |
|
template => $template, |
148 |
|
add_attr => \@attr |
149 |
|
); |
150 |
|
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
151 |
|
return $res; |
152 |
|
}; |
153 |
|
|
154 |
|
$c->stash->{phrase} = $q; |
155 |
|
$c->stash->{attr} = \@attr; |
156 |
|
|
157 |
|
$c->stash->{template} = 'results.tt'; |
158 |
|
} |
159 |
|
|
160 |
=back |
=back |
161 |
|
|
162 |
|
|
163 |
=head1 AUTHOR |
=head1 AUTHOR |
164 |
|
|
165 |
Dobrica Pavlinusic,,, |
Dobrica Pavlinusic C<< <dpavlin@rot13.org> >> |
166 |
|
|
167 |
=head1 LICENSE |
=head1 LICENSE |
168 |
|
|