40 |
|
|
41 |
=item suggest |
=item suggest |
42 |
|
|
43 |
Returns results for URLs like C<search/suggest/FieldName> |
Returns results for REST URIs like: |
44 |
|
|
45 |
It will return field from URL (C<FieldName> in example>) and use |
C<search/suggest?search=FieldName&show=TitleProper&FieldName=query%20string> |
46 |
same filed in paramerers (comming from form or URL) or if it doesn't |
|
47 |
exist field named C<all>. |
It will use C<search> field to filter results (and using additional |
48 |
|
C<FieldName> as value of search) and return C<TitleProper> field |
49 |
|
for results. |
50 |
|
|
51 |
|
If C<search> field has magic value <all>, it will search over all data, not |
52 |
|
just one specified field: |
53 |
|
|
54 |
|
C<search/suggest?search=all&show=TitleProper&all=query%20string> |
55 |
|
|
56 |
=cut |
=cut |
57 |
|
|
58 |
sub suggest : Regex('^search/suggest/*([^/]*)') { |
sub suggest : Local { |
59 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
60 |
|
|
61 |
my $what = $c->request->snippets->[0]; |
my $search = $c->req->params->{search}; |
62 |
|
my $show = $c->req->params->{show}; |
63 |
|
|
64 |
my $log = $c->log; |
my $log = $c->log; |
65 |
|
|
66 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
67 |
|
$c->log->debug( "stash: ", Dumper($c->stash) ); |
68 |
|
$webpac->setup_site( $c->stash->{site} ); |
69 |
|
|
70 |
my $q = $c->req->params->{$what} || |
my $q = $c->req->params->{ $search || 'all' } || $c->response->body("no results"); |
|
$c->req->params->{all} || $c->response->body("no results"); |
|
71 |
|
|
72 |
|
$log->info("search for '$q' in $search and display $show\n"); |
|
$log->info("search for '$q' in $what\n"); |
|
73 |
|
|
74 |
my $max = $c->config->{'hits_for_suggest'}; |
my $max = $c->config->{'hits_for_suggest'}; |
75 |
if (! $max) { |
if (! $max) { |
78 |
$max = 10; |
$max = 10; |
79 |
} |
} |
80 |
|
|
81 |
my @hits = $webpac->search( |
$c->forward('filter_database'); |
82 |
|
|
83 |
|
my $hits = $webpac->search( |
84 |
phrase => $q, |
phrase => $q, |
85 |
|
add_attr => $c->stash->{attr}, |
86 |
|
get_attr => [ $show ], |
87 |
max => $max, |
max => $max, |
|
get_attr => [ $what ], |
|
88 |
); |
); |
89 |
|
|
90 |
my $used; |
my $used; |
91 |
my @suggestions; |
my @suggestions; |
92 |
|
|
93 |
foreach my $res (@hits) { |
foreach my $res (@{$hits}) { |
94 |
my $v = $res->{ $what } || next; |
my $v = $res->{ $show } || next; |
95 |
next if ($used->{ $v }++); |
next if ($used->{ $v }++); |
96 |
push @suggestions, $v; |
push @suggestions, $v; |
97 |
} |
} |
136 |
|
|
137 |
my $params = $c->req->params; |
my $params = $c->req->params; |
138 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
139 |
|
$webpac->setup_site( $c->stash->{site} ); |
140 |
my $log = $c->log; |
my $log = $c->log; |
141 |
|
|
142 |
$log->debug("results got params: " . Dumper( $params ) ); |
$log->debug("results got params: " . Dumper( $params ) ); |
146 |
$log->warn("fixed _page parametar to 1"); |
$log->warn("fixed _page parametar to 1"); |
147 |
} |
} |
148 |
|
|
|
my @attr; |
|
149 |
my @words; |
my @words; |
150 |
# default operator to join fields/words |
# default operator to join fields/words |
151 |
my $operator = 'AND'; |
my $operator = 'AND'; |
171 |
next if ($f eq 'all'); # don't add_attr for magic field all |
next if ($f eq 'all'); # don't add_attr for magic field all |
172 |
|
|
173 |
if ($v !~ /\s/) { |
if ($v !~ /\s/) { |
174 |
push @attr, "$f ISTRINC $v"; |
push @{ $c->stash->{attr} }, "$f ISTRINC $v"; |
175 |
} else { |
} else { |
176 |
map { |
map { |
177 |
push @attr, "$f ISTRINC $_"; |
push @{ $c->stash->{attr} }, "$f ISTRINC $_"; |
178 |
} grep { ! /$hest_op_regex/ } split(/\s+/, $v); |
} grep { ! /$hest_op_regex/ } split(/\s+/, $v); |
179 |
} |
} |
180 |
} |
} |
181 |
|
|
182 |
if ($params->{_database}) { |
$c->forward('filter_database'); |
|
my $type = $c->config->{hyperstraier}->{type} || 'search'; |
|
|
my $attr; |
|
|
if (ref($params->{_database}) eq 'ARRAY') { |
|
|
# FIXME do we need to add $ at end? |
|
|
$attr .= '(' . join("|",@{$params->{_database}}) . ')'; |
|
|
} else { |
|
|
$attr .= $params->{_database}; |
|
|
} |
|
|
push @attr, '@uri STRRX /' . $type . '/' . $attr . '/'; |
|
|
} |
|
183 |
|
|
184 |
my $q = join(" $operator ", @words); |
my $q = join(" $operator ", @words); |
185 |
|
|
195 |
my $res = $webpac->search( |
my $res = $webpac->search( |
196 |
phrase => $q, |
phrase => $q, |
197 |
template => $template, |
template => $template, |
198 |
add_attr => \@attr, |
add_attr => $c->{stash}->{attr}, |
199 |
get_attr => [ '@uri' ], |
get_attr => [ '@uri' ], |
200 |
max => $hits_on_page, |
max => $hits_on_page, |
201 |
page => $params->{'_page'}, |
page => $params->{'_page'}, |
205 |
}; |
}; |
206 |
|
|
207 |
$c->stash->{phrase} = $q; |
$c->stash->{phrase} = $q; |
|
$c->stash->{attr} = \@attr; |
|
208 |
$c->stash->{page} = $params->{'_page'}; |
$c->stash->{page} = $params->{'_page'}; |
209 |
$c->stash->{hits_on_page} = $hits_on_page; |
$c->stash->{hits_on_page} = $hits_on_page; |
210 |
|
|
212 |
|
|
213 |
} |
} |
214 |
|
|
215 |
|
=item filter_database |
216 |
|
|
217 |
|
Takes C<< $c->req->params >> and adds Hyper Estraier |
218 |
|
filters for checked databases to C<< $c->stash->{attr} >>. |
219 |
|
|
220 |
|
=cut |
221 |
|
|
222 |
|
sub filter_database : Private { |
223 |
|
my ( $self, $c ) = @_; |
224 |
|
|
225 |
|
my $params = $c->req->params; |
226 |
|
|
227 |
|
if ($params->{_database}) { |
228 |
|
my $type = $c->config->{hyperstraier}->{type} || 'search'; |
229 |
|
my $attr; |
230 |
|
if (ref($params->{_database}) eq 'ARRAY') { |
231 |
|
# FIXME do we need to add $ at end? |
232 |
|
$attr .= '(' . join("|",@{$params->{_database}}) . ')'; |
233 |
|
} else { |
234 |
|
$attr .= $params->{_database}; |
235 |
|
} |
236 |
|
push @{ $c->stash->{attr} }, '@uri STRRX /' . $type . '/' . $attr . '/'; |
237 |
|
$c->log->debug("filter_database: " . join(",", @{ $c->stash->{attr} }) ); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
} |
242 |
|
|
243 |
=item record |
=item record |
244 |
|
|
245 |
forwarded to C</editor/record> |
forwarded to C</editor/record> |