--- branches/hidra/WebPac.pm 2004/04/18 01:03:27 321
+++ branches/hidra/WebPac.pm 2005/02/16 00:28:54 671
@@ -12,7 +12,7 @@
use Data::Pageset;
use lib '..';
-use index_DBI_cache;
+use index_DBI_filter;
use back2html;
@@ -148,7 +148,7 @@
foreach my $p (@{$pager->pages_in_set()}) {
- next if ($p < 0);
+ next if ($p <= 0);
if($p == $pager->current_page()) {
$pager_jump .= "$p ";
} else {
@@ -183,11 +183,14 @@
my @persist_vars = @_;
my $hidden_vars = '';
foreach my $v (@persist_vars) {
- $hidden_vars .= ''."\n";
+ foreach my $val ($q->param($v)) {
+ next if (! $val || $val eq '');
+ $hidden_vars .= ''."\n";
+ }
}
$tmpl->param('PAGER_HIDDEN', $hidden_vars);
- $tmpl->param('PAGER_JAVASCRIPT', qq{
+ $tmpl->param('PAGER_JAVASCRIPT', qq#
- });
+ #);
}
#--------------------------------------------------------------------------
@@ -228,26 +231,47 @@
my @path_arr = $q->param('path');
my $full = $q->param('full');
- my @persist_vars = ( 'rm' );
+ my @persist_vars = ( 'rm', 'persist_search' );
my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) );
+ my @persist_search_vars;
+ my @url_params_persist;
+ if ($q->param("persist_search")) {
+ @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
+ push @url_params_persist, "persist_search=".$q->url_param("persist_search");
+ push @url_params,"persist_search=".$q->url_param("persist_search");
+ }
+
# support parametars "f" and "v" for start
- for(my $i = ""; $i <=30; $i++) {
+ for(my $i = 0; $i <=30; $i++) {
+
+ $i = '' if ($i == 0);
return show_index($self, $i) if ($q->param("f".$i."_index"));
- next if (! $q->param("v$i"));
+ next if (! $q->param("v$i") || $q->param("v$i") eq '');
next if (! $q->param("f$i"));
+ my $persist = grep(/^$i$/,@persist_search_vars);
+
push @persist_vars, "f$i";
push @persist_vars, "v$i";
push @persist_vars, "e$i" if ($q->param("e$i"));
+ # create url parametars (and persistent ones)
+
push @url_params,"f$i=".$q->url_param("f$i");
+ push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);
+
foreach my $v ($q->url_param("v$i")) {
push @url_params,"v$i=$v";
+ push @url_params_persist,"v$i=$v" if ($persist);
+ }
+
+ if ($q->param("e$i")) {
+ push @url_params,"e$i=".$q->url_param("e$i");
+# push @url_params_persist,"e$i=".$q->url_param("e$i");
}
- push @url_params,"e$i=".$q->url_param("e$i");
my $wc="*"; # swish wildcard
$wc="" if ($i eq ""); # don't apply wildcard on field 0
@@ -268,8 +292,9 @@
# filed e[nr] is exact match bitmask
# 1 = beginning, 2=end, 3=both
- $pre = '"xxbxx ' if ($q->param("e$i") & 1);
- $post = ' xxexx"' if ($q->param("e$i") & 2);
+ my $exact_flag = $q->param("e$i") || 0;
+ $pre = '"xxbxx ' if ($exact_flag & 1);
+ $post = ' xxexx"' if ($exact_flag & 2);
# add qotes on other side
if ($q->param("e$i")) {
$pre = '"' if (! $pre);
@@ -303,7 +328,7 @@
push @s_arr, $q->param("f$i")."_swish".$exact."=(".join(" or ",@swish_q).")";
}
- 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);
$tmpl->param('url_params',"?".join("&",@url_params));
@@ -320,6 +345,13 @@
push @persist_vars, "sort";
}
+ my $sortby = $q->param("sortby");
+ if ($sortby) {
+ $sort = $sortby;
+ push @persist_vars, "sortby";
+ }
+ $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
+
# construct swish query
my $sw_q = join(" and ",@s_arr);
if (@path_arr && $q->param('show_full')) {
@@ -334,9 +366,11 @@
$tmpl->param('full',0);
}
+ my $swish_msg = ' ';
+
# create new swish instance
my $swish = SWISH::API->new($INDEX);
- $swish->AbortLastError if $swish->Error;
+ $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
# execute query and get number of results from SWISH-E
my $search = $swish->New_Search_Object;
@@ -344,12 +378,14 @@
$search->SetSort($sort);
my $results = $search->Execute($sw_q);
- $swish->AbortLastError if $swish->Error;
+ $swish_msg .= $swish->ErrorString." ".$swish->LastErrorMsg if $swish->Error;
my $hits = $results->Hits;
$tmpl->param('hits',$hits);
- $tmpl->param('search',$sw_q);
+ my $search_msg = $sw_q;
+ $search_msg .= ''.$swish_msg.'' if ($swish_msg);
+ $tmpl->param('search', $search_msg);
$tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
$tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
@@ -387,7 +423,7 @@
rank => $result->Property('swishrank')
};
- $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'));
push @pager_data_list, $r;
}
@@ -413,6 +449,8 @@
my $field = $q->param("f$i");
my $limit = $q->param("v$i");
+ my $filter = $q->param("filter");
+
my $html;
my $index = new index_DBI(
@@ -422,16 +460,16 @@
$cfg_global->val('global', 'dbi_passwd') || ''
);
- my $total = $index->count($field,$limit);
+ my $total = $index->count($field,$limit,$filter);
- if (! $total) {
+ if (! defined($total)) {
my $tmpl = $self->load_tmpl(url_ex($q,'no_index.html'));
$tmpl->param('field',$field);
$html = $tmpl->output;
return $html;
}
- 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);
$tmpl->param('field',$field);
$tmpl->param('limit',$limit);
$tmpl->param('total',$total);
@@ -457,7 +495,7 @@
make_pager($q, $tmpl, $pager);
make_pager_vars($q, $tmpl, @persist_vars);
- 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);
$tmpl->param('PAGER_DATA_LIST', \@pager_data_list);
return in_template($q,$tmpl->output);