12 |
use Data::Pageset; |
use Data::Pageset; |
13 |
|
|
14 |
use lib '..'; |
use lib '..'; |
15 |
use index_DBI_cache; |
use index_DBI_filter; |
16 |
use back2html; |
use back2html; |
17 |
|
|
18 |
|
|
148 |
|
|
149 |
|
|
150 |
foreach my $p (@{$pager->pages_in_set()}) { |
foreach my $p (@{$pager->pages_in_set()}) { |
151 |
next if ($p < 0); |
next if ($p <= 0); |
152 |
if($p == $pager->current_page()) { |
if($p == $pager->current_page()) { |
153 |
$pager_jump .= "<b>$p</b> "; |
$pager_jump .= "<b>$p</b> "; |
154 |
} else { |
} else { |
182 |
my $tmpl = shift @_; |
my $tmpl = shift @_; |
183 |
my @persist_vars = @_; |
my @persist_vars = @_; |
184 |
my $hidden_vars = ''; |
my $hidden_vars = ''; |
185 |
|
my $hidden_search = ''; |
186 |
foreach my $v (@persist_vars) { |
foreach my $v (@persist_vars) { |
187 |
foreach my $val ($q->param($v)) { |
foreach my $val ($q->param($v)) { |
188 |
|
next if (! $val || $val eq ''); |
189 |
|
$val =~ s/"/"/g; |
190 |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
191 |
|
$hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm"); |
192 |
} |
} |
193 |
} |
} |
194 |
|
|
195 |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
196 |
$tmpl->param('PAGER_JAVASCRIPT', qq{ |
$tmpl->param('SEARCH_HIDDEN', $hidden_search); |
197 |
|
$tmpl->param('PAGER_JAVASCRIPT', qq# |
198 |
<SCRIPT LANGUAGE="Javascript"> |
<SCRIPT LANGUAGE="Javascript"> |
199 |
<!-- Begin |
<!-- Begin |
200 |
// dummy emulator for HTML::Pager templates |
// dummy emulator for HTML::Pager templates |
203 |
} |
} |
204 |
// End --> |
// End --> |
205 |
</script> |
</script> |
206 |
}); |
#); |
207 |
} |
} |
208 |
|
|
209 |
#-------------------------------------------------------------------------- |
#-------------------------------------------------------------------------- |
228 |
|
|
229 |
my $q = $self->query(); |
my $q = $self->query(); |
230 |
|
|
231 |
|
# submit was reset? |
232 |
|
if ($q->param('reset')) { |
233 |
|
$q->delete_all; |
234 |
|
return $self->show_search_form(); |
235 |
|
} |
236 |
|
|
237 |
# load template for this page |
# load template for this page |
238 |
|
|
239 |
my @s_arr; # all queries are located here |
my @s_arr; # all queries are located here |
241 |
my @path_arr = $q->param('path'); |
my @path_arr = $q->param('path'); |
242 |
my $full = $q->param('full'); |
my $full = $q->param('full'); |
243 |
|
|
244 |
my @persist_vars = ( 'rm' ); |
my @persist_vars = ( 'rm', 'persist_search' ); |
245 |
my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) ); |
my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) ); |
246 |
|
|
247 |
|
my @persist_search_vars; |
248 |
|
my @url_params_persist; |
249 |
|
if ($q->param("persist_search")) { |
250 |
|
@persist_search_vars = split(/\s*,\s*/, $q->param("persist_search")); |
251 |
|
push @url_params_persist, "persist_search=".$q->url_param("persist_search"); |
252 |
|
push @url_params,"persist_search=".$q->url_param("persist_search"); |
253 |
|
} |
254 |
|
|
255 |
# support parametars "f" and "v" for start |
# support parametars "f" and "v" for start |
256 |
for(my $i = ""; $i <=30; $i++) { |
for(my $i = 0; $i <=30; $i++) { |
257 |
|
|
258 |
|
$i = '' if ($i == 0); |
259 |
|
|
260 |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
261 |
|
|
262 |
next if (! $q->param("v$i")); |
next if (! $q->param("v$i") || $q->param("v$i") eq ''); |
263 |
next if (! $q->param("f$i")); |
next if (! $q->param("f$i")); |
264 |
|
|
265 |
|
my $persist = grep(/^$i$/,@persist_search_vars); |
266 |
|
|
267 |
push @persist_vars, "f$i"; |
push @persist_vars, "f$i"; |
268 |
push @persist_vars, "v$i"; |
push @persist_vars, "v$i"; |
269 |
push @persist_vars, "e$i" if ($q->param("e$i")); |
push @persist_vars, "e$i" if ($q->param("e$i")); |
270 |
|
|
271 |
|
# create url parametars (and persistent ones) |
272 |
|
|
273 |
push @url_params,"f$i=".$q->url_param("f$i"); |
push @url_params,"f$i=".$q->url_param("f$i"); |
274 |
|
push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); |
275 |
|
|
276 |
foreach my $v ($q->url_param("v$i")) { |
foreach my $v ($q->url_param("v$i")) { |
277 |
|
# escape quotes so that phrase search work |
278 |
|
$v =~ s/"/%22/g; |
279 |
push @url_params,"v$i=$v"; |
push @url_params,"v$i=$v"; |
280 |
|
push @url_params_persist,"v$i=$v" if ($persist); |
281 |
|
} |
282 |
|
|
283 |
|
if ($q->param("e$i")) { |
284 |
|
push @url_params,"e$i=".$q->url_param("e$i"); |
285 |
|
# push @url_params_persist,"e$i=".$q->url_param("e$i"); |
286 |
} |
} |
|
push @url_params,"e$i=".$q->url_param("e$i"); |
|
287 |
|
|
288 |
my $wc="*"; # swish wildcard |
my $wc="*"; # swish wildcard |
289 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
304 |
|
|
305 |
# filed e[nr] is exact match bitmask |
# filed e[nr] is exact match bitmask |
306 |
# 1 = beginning, 2=end, 3=both |
# 1 = beginning, 2=end, 3=both |
307 |
$pre = '"xxbxx ' if ($q->param("e$i") & 1); |
my $exact_flag = $q->param("e$i") || 0; |
308 |
$post = ' xxexx"' if ($q->param("e$i") & 2); |
$pre = '"xxbxx ' if ($exact_flag & 1); |
309 |
|
$post = ' xxexx"' if ($exact_flag & 2); |
310 |
# add qotes on other side |
# add qotes on other side |
311 |
if ($q->param("e$i")) { |
if ($q->param("e$i")) { |
312 |
$pre = '"' if (! $pre); |
$pre = '"' if (! $pre); |
340 |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")"; |
341 |
} |
} |
342 |
|
|
343 |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0); |
344 |
|
|
345 |
$tmpl->param('url_params',"?".join("&",@url_params)); |
$tmpl->param('url_params',"?".join("&",@url_params)); |
346 |
|
|
357 |
push @persist_vars, "sort"; |
push @persist_vars, "sort"; |
358 |
} |
} |
359 |
|
|
360 |
|
my $sortby = $q->param("sortby"); |
361 |
|
if ($sortby) { |
362 |
|
$sort = $sortby; |
363 |
|
push @persist_vars, "sortby"; |
364 |
|
} |
365 |
|
$tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
366 |
|
|
367 |
# construct swish query |
# construct swish query |
368 |
my $sw_q = join(" and ",@s_arr); |
my $sw_q = join(" and ",@s_arr); |
369 |
if (@path_arr) { |
if (@path_arr && $q->param('show_full')) { |
370 |
$sw_q .= "and (swishdocpath=\""; |
$sw_q .= "and (swishdocpath=\""; |
371 |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
372 |
$sw_q .= "\")"; |
$sw_q .= "\")"; |
373 |
} |
$tmpl->param('full',1); # show full records |
374 |
|
} elsif ($q->param('show_full')) { |
|
if ($q->param('show_full')) { |
|
375 |
# just show full path, no path defined |
# just show full path, no path defined |
376 |
$tmpl->param('full',1); |
$tmpl->param('full',1); |
377 |
} else { |
} else { |
378 |
$tmpl->param('full',0); |
$tmpl->param('full',0); |
379 |
} |
} |
380 |
|
|
381 |
|
my $swish_msg = ' '; |
382 |
|
|
383 |
# create new swish instance |
# create new swish instance |
384 |
my $swish = SWISH::API->new($INDEX); |
my $swish = SWISH::API->new($INDEX); |
385 |
$swish->AbortLastError if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
386 |
|
|
387 |
# execute query and get number of results from SWISH-E |
# execute query and get number of results from SWISH-E |
388 |
my $search = $swish->New_Search_Object; |
my $search = $swish->New_Search_Object; |
390 |
$search->SetSort($sort); |
$search->SetSort($sort); |
391 |
|
|
392 |
my $results = $search->Execute($sw_q); |
my $results = $search->Execute($sw_q); |
393 |
$swish->AbortLastError if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
394 |
|
|
395 |
my $hits = $results->Hits; |
my $hits = $results->Hits; |
396 |
|
|
397 |
$tmpl->param('hits',$hits); |
$tmpl->param('hits',$hits); |
398 |
$tmpl->param('search',$sw_q); |
my $search_msg = $sw_q; |
399 |
|
$search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg); |
400 |
|
$tmpl->param('search', $search_msg); |
401 |
|
|
402 |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
403 |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
435 |
rank => $result->Property('swishrank') |
rank => $result->Property('swishrank') |
436 |
}; |
}; |
437 |
|
|
438 |
$r->{html} = back2html($from_utf8->convert($result->Property('html'))) if ($q->param('show_full')); |
$r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full')); |
439 |
|
|
440 |
push @pager_data_list, $r; |
push @pager_data_list, $r; |
441 |
} |
} |
461 |
my $field = $q->param("f$i"); |
my $field = $q->param("f$i"); |
462 |
my $limit = $q->param("v$i"); |
my $limit = $q->param("v$i"); |
463 |
|
|
464 |
|
my $filter = $q->param("filter"); |
465 |
|
|
466 |
my $html; |
my $html; |
467 |
|
|
468 |
my $index = new index_DBI( |
my $index = new index_DBI( |
472 |
$cfg_global->val('global', 'dbi_passwd') || '' |
$cfg_global->val('global', 'dbi_passwd') || '' |
473 |
); |
); |
474 |
|
|
475 |
my $total = $index->count($field,$limit); |
my $total = $index->count($field,$limit,$filter); |
476 |
|
|
477 |
if (! $total) { |
if (! defined($total)) { |
478 |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
479 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
480 |
$html = $tmpl->output; |
$html = $tmpl->output; |
481 |
return $html; |
return $html; |
482 |
} |
} |
483 |
|
|
484 |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1); |
my $tmpl = $self->load_tmpl(url_ex($q,'index_res.html'), global_vars => 1, die_on_bad_params => 0); |
485 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
486 |
$tmpl->param('limit',$limit); |
$tmpl->param('limit',$limit); |
487 |
$tmpl->param('total',$total); |
$tmpl->param('total',$total); |
488 |
|
$tmpl->param('filter',$filter); |
489 |
|
|
490 |
# FIXME I should set offset and leave out limit from fetch!! |
# FIXME I should set offset and leave out limit from fetch!! |
491 |
# if (! $q->param("PAGER_offset") { |
# if (! $q->param("PAGER_offset") { |
508 |
make_pager($q, $tmpl, $pager); |
make_pager($q, $tmpl, $pager); |
509 |
make_pager_vars($q, $tmpl, @persist_vars); |
make_pager_vars($q, $tmpl, @persist_vars); |
510 |
|
|
511 |
my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page); |
my @pager_data_list = $index->fetch($field,$limit, $pager->first - 1, $pager->entries_on_this_page, $filter); |
512 |
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
513 |
|
|
514 |
return in_template($q,$tmpl->output); |
return in_template($q,$tmpl->output); |