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 { |
184 |
my $hidden_vars = ''; |
my $hidden_vars = ''; |
185 |
foreach my $v (@persist_vars) { |
foreach my $v (@persist_vars) { |
186 |
foreach my $val ($q->param($v)) { |
foreach my $val ($q->param($v)) { |
187 |
|
next if (! $val || $val eq ''); |
188 |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
$hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n"; |
189 |
} |
} |
190 |
} |
} |
191 |
|
|
192 |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
$tmpl->param('PAGER_HIDDEN', $hidden_vars); |
193 |
$tmpl->param('PAGER_JAVASCRIPT', qq{ |
$tmpl->param('PAGER_JAVASCRIPT', qq# |
194 |
<SCRIPT LANGUAGE="Javascript"> |
<SCRIPT LANGUAGE="Javascript"> |
195 |
<!-- Begin |
<!-- Begin |
196 |
// dummy emulator for HTML::Pager templates |
// dummy emulator for HTML::Pager templates |
199 |
} |
} |
200 |
// End --> |
// End --> |
201 |
</script> |
</script> |
202 |
}); |
#); |
203 |
} |
} |
204 |
|
|
205 |
#-------------------------------------------------------------------------- |
#-------------------------------------------------------------------------- |
231 |
my @path_arr = $q->param('path'); |
my @path_arr = $q->param('path'); |
232 |
my $full = $q->param('full'); |
my $full = $q->param('full'); |
233 |
|
|
234 |
my @persist_vars = ( 'rm' ); |
my @persist_vars = ( 'rm', 'persist_search' ); |
235 |
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) ); |
236 |
|
|
237 |
|
my @persist_search_vars; |
238 |
|
my @url_params_persist; |
239 |
|
if ($q->param("persist_search")) { |
240 |
|
@persist_search_vars = split(/\s*,\s*/, $q->param("persist_search")); |
241 |
|
push @url_params_persist, "persist_search=".$q->url_param("persist_search"); |
242 |
|
push @url_params,"persist_search=".$q->url_param("persist_search"); |
243 |
|
} |
244 |
|
|
245 |
# support parametars "f" and "v" for start |
# support parametars "f" and "v" for start |
246 |
for(my $i = ""; $i <=30; $i++) { |
for(my $i = 0; $i <=30; $i++) { |
247 |
|
|
248 |
|
$i = '' if ($i == 0); |
249 |
|
|
250 |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
251 |
|
|
252 |
next if (! $q->param("v$i")); |
next if (! $q->param("v$i") || $q->param("v$i") eq ''); |
253 |
next if (! $q->param("f$i")); |
next if (! $q->param("f$i")); |
254 |
|
|
255 |
|
my $persist = grep(/^$i$/,@persist_search_vars); |
256 |
|
|
257 |
push @persist_vars, "f$i"; |
push @persist_vars, "f$i"; |
258 |
push @persist_vars, "v$i"; |
push @persist_vars, "v$i"; |
259 |
push @persist_vars, "e$i" if ($q->param("e$i")); |
push @persist_vars, "e$i" if ($q->param("e$i")); |
260 |
|
|
261 |
|
# create url parametars (and persistent ones) |
262 |
|
|
263 |
push @url_params,"f$i=".$q->url_param("f$i"); |
push @url_params,"f$i=".$q->url_param("f$i"); |
264 |
|
push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist); |
265 |
|
|
266 |
foreach my $v ($q->url_param("v$i")) { |
foreach my $v ($q->url_param("v$i")) { |
267 |
push @url_params,"v$i=$v"; |
push @url_params,"v$i=$v"; |
268 |
|
push @url_params_persist,"v$i=$v" if ($persist); |
269 |
|
} |
270 |
|
|
271 |
|
if ($q->param("e$i")) { |
272 |
|
push @url_params,"e$i=".$q->url_param("e$i"); |
273 |
|
# push @url_params_persist,"e$i=".$q->url_param("e$i"); |
274 |
} |
} |
|
push @url_params,"e$i=".$q->url_param("e$i"); |
|
275 |
|
|
276 |
my $wc="*"; # swish wildcard |
my $wc="*"; # swish wildcard |
277 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
$wc="" if ($i eq ""); # don't apply wildcard on field 0 |
292 |
|
|
293 |
# filed e[nr] is exact match bitmask |
# filed e[nr] is exact match bitmask |
294 |
# 1 = beginning, 2=end, 3=both |
# 1 = beginning, 2=end, 3=both |
295 |
$pre = '"xxbxx ' if ($q->param("e$i") & 1); |
my $exact_flag = $q->param("e$i") || 0; |
296 |
$post = ' xxexx"' if ($q->param("e$i") & 2); |
$pre = '"xxbxx ' if ($exact_flag & 1); |
297 |
|
$post = ' xxexx"' if ($exact_flag & 2); |
298 |
# add qotes on other side |
# add qotes on other side |
299 |
if ($q->param("e$i")) { |
if ($q->param("e$i")) { |
300 |
$pre = '"' if (! $pre); |
$pre = '"' if (! $pre); |
345 |
push @persist_vars, "sort"; |
push @persist_vars, "sort"; |
346 |
} |
} |
347 |
|
|
348 |
|
my $sortby = $q->param("sortby"); |
349 |
|
if ($sortby) { |
350 |
|
$sort = $sortby; |
351 |
|
push @persist_vars, "sortby"; |
352 |
|
} |
353 |
|
$tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr)); |
354 |
|
|
355 |
# construct swish query |
# construct swish query |
356 |
my $sw_q = join(" and ",@s_arr); |
my $sw_q = join(" and ",@s_arr); |
357 |
if (@path_arr) { |
if (@path_arr && $q->param('show_full')) { |
358 |
$sw_q .= "and (swishdocpath=\""; |
$sw_q .= "and (swishdocpath=\""; |
359 |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
$sw_q .= join("\" or swishdocpath=\"",@path_arr); |
360 |
$sw_q .= "\")"; |
$sw_q .= "\")"; |
361 |
} |
$tmpl->param('full',1); # show full records |
362 |
|
} elsif ($q->param('show_full')) { |
|
if ($q->param('show_full')) { |
|
363 |
# just show full path, no path defined |
# just show full path, no path defined |
364 |
$tmpl->param('full',1); |
$tmpl->param('full',1); |
365 |
} else { |
} else { |
366 |
$tmpl->param('full',0); |
$tmpl->param('full',0); |
367 |
} |
} |
368 |
|
|
369 |
|
my $swish_msg = ' '; |
370 |
|
|
371 |
# create new swish instance |
# create new swish instance |
372 |
my $swish = SWISH::API->new($INDEX); |
my $swish = SWISH::API->new($INDEX); |
373 |
$swish->AbortLastError if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
374 |
|
|
375 |
# execute query and get number of results from SWISH-E |
# execute query and get number of results from SWISH-E |
376 |
my $search = $swish->New_Search_Object; |
my $search = $swish->New_Search_Object; |
378 |
$search->SetSort($sort); |
$search->SetSort($sort); |
379 |
|
|
380 |
my $results = $search->Execute($sw_q); |
my $results = $search->Execute($sw_q); |
381 |
$swish->AbortLastError if $swish->Error; |
$swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error; |
382 |
|
|
383 |
my $hits = $results->Hits; |
my $hits = $results->Hits; |
384 |
|
|
385 |
$tmpl->param('hits',$hits); |
$tmpl->param('hits',$hits); |
386 |
$tmpl->param('search',$sw_q); |
my $search_msg = $sw_q; |
387 |
|
$search_msg .= '<em>'.$swish_msg.'</em>' if ($swish_msg); |
388 |
|
$tmpl->param('search', $search_msg); |
389 |
|
|
390 |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0); |
391 |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0); |
423 |
rank => $result->Property('swishrank') |
rank => $result->Property('swishrank') |
424 |
}; |
}; |
425 |
|
|
426 |
$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')); |
427 |
|
|
428 |
push @pager_data_list, $r; |
push @pager_data_list, $r; |
429 |
} |
} |
449 |
my $field = $q->param("f$i"); |
my $field = $q->param("f$i"); |
450 |
my $limit = $q->param("v$i"); |
my $limit = $q->param("v$i"); |
451 |
|
|
452 |
|
my $filter = $q->param("filter"); |
453 |
|
|
454 |
my $html; |
my $html; |
455 |
|
|
456 |
my $index = new index_DBI( |
my $index = new index_DBI( |
460 |
$cfg_global->val('global', 'dbi_passwd') || '' |
$cfg_global->val('global', 'dbi_passwd') || '' |
461 |
); |
); |
462 |
|
|
463 |
my $total = $index->count($field,$limit); |
my $total = $index->count($field,$limit,$filter); |
464 |
|
|
465 |
if (! $total) { |
if (! defined($total)) { |
466 |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html')); |
467 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
468 |
$html = $tmpl->output; |
$html = $tmpl->output; |
495 |
make_pager($q, $tmpl, $pager); |
make_pager($q, $tmpl, $pager); |
496 |
make_pager_vars($q, $tmpl, @persist_vars); |
make_pager_vars($q, $tmpl, @persist_vars); |
497 |
|
|
498 |
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); |
499 |
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list); |
500 |
|
|
501 |
return in_template($q,$tmpl->output); |
return in_template($q,$tmpl->output); |