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; |
10 |
require Unicode::Map8; |
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(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; |
32 |
$self->run_modes( |
$self->run_modes( |
33 |
'search' => 'show_search_form', |
'search' => 'show_search_form', |
34 |
'results' => 'show_results_list', |
'results' => 'show_results_list', |
35 |
# 'user' => 'show_user_detail' |
# 'user' => 'show_user_detail', |
36 |
|
'index' => 'show_index', |
37 |
); |
); |
38 |
$self->start_mode('search'); |
$self->start_mode('search'); |
39 |
$self->mode_param('rm'); |
$self->mode_param('rm'); |
64 |
my @swish_results; # results from swish |
my @swish_results; # results from swish |
65 |
|
|
66 |
# load template for this page |
# load template for this page |
|
my $tmpl = $self->load_tmpl('results.html'); |
|
67 |
|
|
68 |
my @s_arr; # all queries are located here |
my @s_arr; # all queries are located here |
69 |
|
|
70 |
for(my $i = 1; $i <=10; $i++) { |
for(my $i = 1; $i <=10; $i++) { |
71 |
|
|
72 |
last if (! $q->param("f$i")); |
return show_index($self, $i) if ($q->param("f".$i."_index")); |
73 |
|
next if (! $q->param("f$i")); |
74 |
next if (! $q->param("v$i")); |
next if (! $q->param("v$i")); |
75 |
|
|
76 |
# re-write query from +/- to and/and not |
# re-write query from +/- to and/and not |
92 |
} |
} |
93 |
} |
} |
94 |
|
|
95 |
push @s_arr,$q->param("f$i")."=($s)"; |
push @s_arr,$q->param("f$i")."_swish=($s)"; |
96 |
} |
} |
97 |
|
|
98 |
my $l2_map = Unicode::Map8->new($CHARSET) || die; |
my $tmpl = $self->load_tmpl('results.html'); |
|
my $us = Unicode::String->new(); |
|
99 |
|
|
100 |
# call swish |
# call swish |
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 |
|
|
|
$us->utf8($hit->swishtitle); |
|
|
|
|
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 => $l2_map->to8($us->utf16), |
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, |
165 |
return $html; |
return $html; |
166 |
} |
} |
167 |
|
|
168 |
|
sub show_index { |
169 |
|
my $self = shift; |
170 |
|
my $i = shift; # field number |
171 |
|
|
172 |
|
my $q = $self->query(); |
173 |
|
|
174 |
|
my $field = $q->param("f$i"); |
175 |
|
my $limit = $q->param("v$i"); |
176 |
|
|
177 |
|
my $html; |
178 |
|
|
179 |
|
my $index = new index_DBI(); |
180 |
|
|
181 |
|
my $total = $index->check($field); |
182 |
|
if (! $total) { |
183 |
|
my $tmpl = $self->load_tmpl('no_index.html'); |
184 |
|
$tmpl->param('field',$field); |
185 |
|
$html = $tmpl->output; |
186 |
|
return $html; |
187 |
|
} |
188 |
|
|
189 |
|
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 |
|
my $pager = HTML::Pager->new( |
195 |
|
query => $q, |
196 |
|
get_data_callback => sub { |
197 |
|
my ($offset, $rows) = @_; |
198 |
|
|
199 |
|
my @result = $index->fetch($field,'item',$limit, $offset, $rows); |
200 |
|
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 $pager->output; |
214 |
|
} |
215 |
|
|
216 |
1; |
1; |