6 |
use HTML::Pager; |
use HTML::Pager; |
7 |
use HTML::FillInForm; |
use HTML::FillInForm; |
8 |
use SWISH; |
use SWISH; |
9 |
use Unicode::String qw(utf8 utf16); |
use Text::Iconv; |
|
require Unicode::Map8; |
|
10 |
use DBI; |
use DBI; |
11 |
|
|
12 |
|
use lib '..'; |
13 |
|
use index_DBI; |
14 |
|
use back2html; |
15 |
|
|
16 |
# configuration options |
# configuration options |
17 |
# FIX: they really should go in configuration file! |
# FIX: they really should go in configuration file! |
18 |
my $TEMPLATE_PATH = '/data/webpac/template_html'; |
my $TEMPLATE_PATH = '/data/webpac/template_html'; |
19 |
my $CHARSET = 'ISO-8859-2'; |
my $CHARSET = 'ISO-8859-2'; |
20 |
my $SWISH = '/data/swish/swish-e'; |
my $SWISH = '/usr/bin/swish-e'; |
21 |
my $INDEX = '/data/webpac/index/isis.index'; |
my $INDEX = '/data/webpac/index/isis.index'; |
22 |
my $MAX_HITS = 500; |
my $MAX_HITS = 500; |
23 |
my $ON_PAGE = 10; |
my $ON_PAGE = 10; |
24 |
|
|
25 |
|
Text::Iconv->raise_error(0); # Conversion errors raise exceptions |
26 |
|
|
27 |
|
my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET); |
28 |
|
|
29 |
sub setup { |
sub setup { |
30 |
my $self = shift; |
my $self = shift; |
91 |
$s.="$_* "; |
$s.="$_* "; |
92 |
} |
} |
93 |
} |
} |
94 |
|
$s =~ s/\*+/*/g; |
95 |
|
|
96 |
push @s_arr,$q->param("f$i")."_swish=($s)"; |
push @s_arr,$q->param("f$i")."_swish=($s)"; |
97 |
} |
} |
98 |
|
|
99 |
my $tmpl = $self->load_tmpl('results.html'); |
my $tmpl = $self->load_tmpl('results.html'); |
100 |
|
|
|
my $l2_map = Unicode::Map8->new($CHARSET) || die; |
|
|
my $us = Unicode::String->new(); |
|
|
|
|
101 |
# call swish |
# call swish |
102 |
my $sh = SWISH->connect('Fork', |
my $sh = SWISH->connect('Fork', |
103 |
prog => $SWISH, |
prog => $SWISH, |
104 |
indexes => $INDEX, |
indexes => $INDEX, |
105 |
#properties => [qw/god br nr/], |
properties => [qw/swishdocpath swishrank swishtitle headline html/], |
106 |
results => sub { |
results => sub { |
107 |
my ($sh,$hit) = @_; |
my ($sh,$hit) = @_; |
108 |
|
|
|
$us->utf8($hit->swishtitle); |
|
|
|
|
109 |
push @swish_results, { |
push @swish_results, { |
110 |
nr => ($#swish_results + 2), |
nr => ($#swish_results + 2), |
111 |
path => $hit->swishdocpath, |
path => $hit->swishdocpath, |
112 |
title => $l2_map->to8($us->utf16), |
# headline => $from_utf8->convert($hit->headline), |
113 |
|
# html => back2html($from_utf8->convert($hit->html)), |
114 |
|
headline => $hit->headline, |
115 |
|
html => back2html($hit->html), |
116 |
rank => $hit->swishrank }; |
rank => $hit->swishrank }; |
117 |
|
|
|
# my @fields = $hit->field_names; |
|
|
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
|
118 |
}, |
}, |
119 |
#startnum => 0, |
#startnum => 0, |
120 |
maxhits => $MAX_HITS, |
maxhits => $MAX_HITS, |
174 |
|
|
175 |
my $q = $self->query(); |
my $q = $self->query(); |
176 |
|
|
177 |
|
my $field = $q->param("f$i"); |
178 |
|
my $limit = $q->param("v$i"); |
179 |
|
|
180 |
my $html; |
my $html; |
181 |
|
|
182 |
$html .= "show index of ".$q->param("f$i")." for ".$q->param("v$i"); |
my $index = new index_DBI(); |
183 |
|
|
184 |
|
my $total = $index->check($field); |
185 |
|
if (! $total) { |
186 |
|
my $tmpl = $self->load_tmpl('no_index.html'); |
187 |
|
$tmpl->param('field',$field); |
188 |
|
$html = $tmpl->output; |
189 |
|
return $html; |
190 |
|
} |
191 |
|
|
192 |
return $html; |
my $tmpl = $self->load_tmpl('index_res.html'); |
193 |
|
$tmpl->param('field',$field); |
194 |
|
$tmpl->param('limit',$limit); |
195 |
|
$tmpl->param('total',$total); |
196 |
|
|
197 |
|
# FIX: I should set offset and leave out limit from fetch!! |
198 |
|
# if (! $q->param("PAGER_offset") { |
199 |
|
# $q->param("Pager_offet) |
200 |
|
# } |
201 |
|
|
202 |
|
my $pager = HTML::Pager->new( |
203 |
|
query => $q, |
204 |
|
get_data_callback => sub { |
205 |
|
my ($offset, $rows) = @_; |
206 |
|
|
207 |
|
my @result = $index->fetch($field,'item',$limit, $offset, $rows); |
208 |
|
return \@result; |
209 |
|
}, |
210 |
|
rows => $total, |
211 |
|
page_size => $ON_PAGE, |
212 |
|
persist_vars => [ |
213 |
|
'rm', |
214 |
|
"f$i", "v$i", "f".$i."_index", |
215 |
|
'offset', |
216 |
|
], |
217 |
|
debug => 1, |
218 |
|
template => $tmpl, |
219 |
|
); |
220 |
|
|
221 |
|
return $pager->output; |
222 |
} |
} |
223 |
|
|
224 |
1; |
1; |