3 use base 'CGI::Application';
9 use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
16 # configuration options
17 # FIX: they really should go in configuration file!
18 my $TEMPLATE_PATH = '/data/webpac/template_html';
19 my $CHARSET = 'ISO-8859-2';
20 my $SWISH = '/usr/bin/swish-e';
21 my $INDEX = '/data/webpac/index/isis.index';
28 $self->tmpl_path($TEMPLATE_PATH);
30 'search' => 'show_search_form',
31 'results' => 'show_results_list',
32 # 'user' => 'show_user_detail',
33 'index' => 'show_index',
35 $self->start_mode('search');
36 $self->mode_param('rm');
38 $self->header_props(-charset=>$CHARSET);
41 sub show_search_form {
44 # Get the CGI.pm query object
45 my $q = $self->query();
47 my $tmpl = $self->load_tmpl('search.html');
48 my $html = $tmpl->output;
50 my $fif = new HTML::FillInForm;
52 return $fif->fill(scalarref => \$html, fobject => $q,
56 sub show_results_list {
59 my $q = $self->query();
61 my @swish_results; # results from swish
63 # load template for this page
65 my @s_arr; # all queries are located here
67 for(my $i = 1; $i <=10; $i++) {
69 return show_index($self, $i) if ($q->param("f".$i."_index"));
70 next if (! $q->param("f$i"));
71 next if (! $q->param("v$i"));
73 # re-write query from +/- to and/and not
75 my $search = $q->param("v$i");
76 while ($search =~ s/\s*("[^"]+")\s*/ /) {
82 foreach (split(/\s+/,$search)) {
83 if (m/^([+-])(\S+)/) {
84 $s.= ($s) ? "and " : "";
85 $s.="not " if ($1 eq "-");
92 push @s_arr,$q->param("f$i")."_swish=($s)";
95 my $tmpl = $self->load_tmpl('results.html');
98 my $sh = SWISH->connect('Fork',
101 properties => [qw/swishdocpath swishrank swishtitle headline html/],
105 push @swish_results, {
106 nr => ($#swish_results + 2),
107 path => $hit->swishdocpath,
108 headline => from_utf8({ -string => $hit->headline, -charset => $CHARSET }),
109 html => back2html(from_utf8({ -string => $hit->html, -charset => $CHARSET })),
110 rank => $hit->swishrank };
114 maxhits => $MAX_HITS,
117 die $SWISH::errstr unless $sh;
119 my $hits = $sh->query(join(" and ",@s_arr)) || 0; # FIX: and/or
121 $tmpl->param('hits',$hits);
122 $tmpl->param('search',join(" and ",@s_arr));
124 # create a Pager object
125 my $pager = HTML::Pager->new(
126 # required parameters
128 get_data_callback => sub {
129 my ($offset, $rows) = @_;
132 for (my $i=0; $i<$rows; $i++) {
133 push @result, $swish_results[$offset+$i] if $swish_results[$offset+$i];
138 page_size => $ON_PAGE,
139 # some optional parameters
152 #cell_space_color => '#000000',
153 #cell_background_color => '#ffffff',
154 #nav_background_color => '#dddddd',
155 #javascript_presubmit => 'last_minute_javascript()',
160 my $html = $pager->output;
167 my $i = shift; # field number
169 my $q = $self->query();
171 my $field = $q->param("f$i");
172 my $limit = $q->param("v$i");
176 my $index = new index_DBI();
178 my $total = $index->check($field);
180 my $tmpl = $self->load_tmpl('no_index.html');
181 $tmpl->param('field',$field);
182 $html = $tmpl->output;
186 my $tmpl = $self->load_tmpl('index_res.html');
187 $tmpl->param('field',$field);
188 $tmpl->param('limit',$limit);
189 $tmpl->param('total',$total);
191 my $pager = HTML::Pager->new(
193 get_data_callback => sub {
194 my ($offset, $rows) = @_;
196 my @result = $index->fetch($field,'item',$limit, $offset, $rows);
200 page_size => $ON_PAGE,
203 "f$i", "v$i", "f".$i."_index",
210 return $pager->output;