6 |
use HTML::Pager; |
use HTML::Pager; |
7 |
use HTML::FillInForm; |
use HTML::FillInForm; |
8 |
use SWISH; |
use SWISH; |
9 |
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset); |
use Text::Iconv; |
10 |
use DBI; |
use DBI; |
11 |
|
|
12 |
use lib '..'; |
use lib '..'; |
13 |
use index_DBI; |
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 = '/usr/local/bin/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(1); # 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; |
101 |
my $sh = SWISH->connect('Fork', |
my $sh = SWISH->connect('Fork', |
102 |
prog => $SWISH, |
prog => $SWISH, |
103 |
indexes => $INDEX, |
indexes => $INDEX, |
104 |
#properties => [qw/god br nr/], |
properties => [qw/swishdocpath swishrank swishtitle headline html/], |
105 |
results => sub { |
results => sub { |
106 |
my ($sh,$hit) = @_; |
my ($sh,$hit) = @_; |
107 |
|
|
108 |
push @swish_results, { |
push @swish_results, { |
109 |
nr => ($#swish_results + 2), |
nr => ($#swish_results + 2), |
110 |
path => $hit->swishdocpath, |
path => $hit->swishdocpath, |
111 |
title => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }), |
headline => $from_utf8->convert($hit->headline), |
112 |
|
html => back2html($from_utf8->convert($hit->html)), |
113 |
rank => $hit->swishrank }; |
rank => $hit->swishrank }; |
114 |
|
|
|
# my @fields = $hit->field_names; |
|
|
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
|
115 |
}, |
}, |
116 |
#startnum => 0, |
#startnum => 0, |
117 |
maxhits => $MAX_HITS, |
maxhits => $MAX_HITS, |
174 |
my $field = $q->param("f$i"); |
my $field = $q->param("f$i"); |
175 |
my $limit = $q->param("v$i"); |
my $limit = $q->param("v$i"); |
176 |
|
|
|
|
|
177 |
my $html; |
my $html; |
178 |
|
|
179 |
my $index = new index_DBI(); |
my $index = new index_DBI(); |
180 |
|
|
181 |
if (! $index->check($field)) { |
my $total = $index->check($field); |
182 |
|
if (! $total) { |
183 |
my $tmpl = $self->load_tmpl('no_index.html'); |
my $tmpl = $self->load_tmpl('no_index.html'); |
184 |
$tmpl->param('field',$field); |
$tmpl->param('field',$field); |
185 |
$html = $tmpl->output; |
$html = $tmpl->output; |
186 |
return $html; |
return $html; |
187 |
} |
} |
188 |
|
|
189 |
my @index_arr = $index->fetch($field,'item',$limit); |
my $tmpl = $self->load_tmpl('index_res.html'); |
190 |
|
$tmpl->param('field',$field); |
191 |
|
$tmpl->param('limit',$limit); |
192 |
|
$tmpl->param('total',$total); |
193 |
|
|
194 |
$html .= "show index of <i>$field</i>"; |
my $pager = HTML::Pager->new( |
195 |
$html .= " for <i>$limit</i>" if ($limit); |
query => $q, |
196 |
|
get_data_callback => sub { |
197 |
|
my ($offset, $rows) = @_; |
198 |
|
|
199 |
while (my $row = shift @index_arr) { |
my @result = $index->fetch($field,'item',$limit, $offset, $rows); |
200 |
$html .= "<br>".$row->{item}."\n"; |
return \@result; |
201 |
} |
}, |
202 |
|
rows => $total, |
203 |
|
page_size => $ON_PAGE, |
204 |
|
persist_vars => [ |
205 |
|
'rm', |
206 |
|
"f$i", "v$i", "f".$i."_index", |
207 |
|
'offset', |
208 |
|
], |
209 |
|
debug => 1, |
210 |
|
template => $tmpl, |
211 |
|
); |
212 |
|
|
213 |
return $html; |
return $pager->output; |
214 |
} |
} |
215 |
|
|
216 |
1; |
1; |