7 |
use Data::Dumper; |
use Data::Dumper; |
8 |
|
|
9 |
use lib '/data/webpac2/lib'; |
use lib '/data/webpac2/lib'; |
10 |
use WebPAC::Search::Estraier; |
use WebPAC::Search::Estraier 0.03; |
11 |
|
|
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
32 |
|
|
33 |
sub default : Private { |
sub default : Private { |
34 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
35 |
|
|
36 |
|
$c->log->debug("default search got param: ".Dumper($c->req->params)); |
37 |
|
|
38 |
$c->stash->{template} = 'search.tt'; |
$c->stash->{template} = 'search.tt'; |
39 |
} |
} |
40 |
|
|
58 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
59 |
|
|
60 |
my $q = $c->req->params->{$what} || |
my $q = $c->req->params->{$what} || |
61 |
$c->req->params->{all} || $c->res->output("no results"); |
$c->req->params->{all} || $c->response->body("no results"); |
62 |
|
|
63 |
|
|
64 |
$log->info("search for '$q' in $what\n"); |
$log->info("search for '$q' in $what\n"); |
87 |
|
|
88 |
$log->debug( ($#suggestions + 1) . " unique hits returned"); |
$log->debug( ($#suggestions + 1) . " unique hits returned"); |
89 |
|
|
90 |
$c->res->body( $c->prototype->auto_complete_result( \@suggestions ) ); |
$c->response->body( $c->prototype->auto_complete_result( \@suggestions ) ); |
91 |
} |
} |
92 |
|
|
93 |
|
|
|
# specify all Hyper Estraier operators which should stop this module |
|
|
# from splitting search query and joining it with default operator |
|
|
my $hest_op_regex = qr/(:?\[(:?BW|EW|RX)\]|AND|OR|ANDNOT)/; |
|
|
|
|
94 |
=item results |
=item results |
95 |
|
|
96 |
Mothod which uses C<Model::WebPAC> and returns results for search query |
Returns results for search query |
97 |
|
|
98 |
=cut |
=cut |
99 |
|
|
100 |
sub results : Local { |
sub results : Local { |
101 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
102 |
|
|
|
my $webpac = $c->comp('Model::WebPAC'); |
|
103 |
my $params = $c->req->params; |
my $params = $c->req->params; |
104 |
|
|
105 |
|
# oh, client didn't have ability to setup AJAX, fallback to |
106 |
|
# page refresh |
107 |
|
if (! $params->{'_ajax'}) { |
108 |
|
$params->{_ajax} = 1; |
109 |
|
$c->stash->{results} = $c->subreq('/search/results/ajax', {}, $params); |
110 |
|
$c->stash->{template} = 'search.tt'; |
111 |
|
} else { |
112 |
|
$c->forward('/search/results/ajax'); |
113 |
|
$c->stash->{template} = 'results.tt'; |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
=item results_ajax |
119 |
|
|
120 |
|
Private method which uses C<Model::WebPAC> and returns results for search |
121 |
|
query It generatets just I<inner> HTML for results div, so it has C<_ajax> |
122 |
|
in name. |
123 |
|
|
124 |
|
=cut |
125 |
|
|
126 |
|
# specify all Hyper Estraier operators which should stop this module |
127 |
|
# from splitting search query and joining it with default operator |
128 |
|
my $hest_op_regex = qr/(:?\[(:?BW|EW|RX)\]|AND|OR|ANDNOT)/o; |
129 |
|
|
130 |
|
sub results_ajax : Path( 'results/ajax' ) { |
131 |
|
my ( $self, $c ) = @_; |
132 |
|
|
133 |
|
my $params = $c->req->params; |
134 |
|
my $webpac = $c->comp('Model::WebPAC'); |
135 |
my $log = $c->log; |
my $log = $c->log; |
136 |
|
|
137 |
$log->debug("results got params: " . Dumper( $params ) ); |
$log->debug("results got params: " . Dumper( $params ) ); |
138 |
|
|
139 |
|
if (! $params->{_page} || $params->{_page} < 1) { |
140 |
|
$params->{_page} = 1; |
141 |
|
$log->warn("fixed _page parametar to 1"); |
142 |
|
} |
143 |
|
|
144 |
my @attr; |
my @attr; |
145 |
my @words; |
my @words; |
146 |
# default operator to join fields/words |
# default operator to join fields/words |
181 |
|
|
182 |
$log->die("can't find _template or default from configuration!") unless ($template); |
$log->die("can't find _template or default from configuration!") unless ($template); |
183 |
|
|
184 |
$log->debug("using template $template"); |
my $hits_on_page = $c->config->{'hyperestraier'}->{'hits_on_page'} || 10; |
185 |
|
|
186 |
|
$log->debug("using template $template to produce $hits_on_page results"); |
187 |
|
|
188 |
$c->stash->{html_results} = sub { |
$c->stash->{html_results} = sub { |
189 |
my $res = $webpac->search( |
my $res = $webpac->search( |
191 |
template => $template, |
template => $template, |
192 |
add_attr => \@attr, |
add_attr => \@attr, |
193 |
get_attr => [ '@uri' ], |
get_attr => [ '@uri' ], |
194 |
max => $c->config->{'hits_on_page'}, |
max => $hits_on_page, |
195 |
|
page => $params->{'_page'}, |
196 |
); |
); |
197 |
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
198 |
return $res; |
return $res; |
199 |
}; |
}; |
200 |
|
|
201 |
$c->stash->{phrase} = $q; |
$c->stash->{phrase} = $q; |
202 |
$c->stash->{attr} = \@attr; |
$c->stash->{attr} = \@attr; |
203 |
|
$c->stash->{page} = $params->{'_page'}; |
204 |
|
$c->stash->{hits_on_page} = $hits_on_page; |
205 |
|
|
206 |
$c->stash->{template} = 'results.tt'; |
$c->stash->{template} = 'results.tt'; |
207 |
|
|
208 |
} |
} |
209 |
|
|
210 |
=back |
=item record |
211 |
|
|
212 |
|
forwarded to C</editor/record> |
213 |
|
|
214 |
|
=cut |
215 |
|
|
216 |
|
sub record : Local { |
217 |
|
my ( $self, $c ) = @_; |
218 |
|
|
219 |
|
$c->forward( '/editor/record' ); |
220 |
|
} |
221 |
|
|
222 |
|
=back |
223 |
|
|
224 |
=head1 AUTHOR |
=head1 AUTHOR |
225 |
|
|