3 use base 'CGI::Application';
9 use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
15 # configuration options
16 # FIX: they really should go in configuration file!
17 my $TEMPLATE_PATH = '/data/webpac/template_html';
18 my $CHARSET = 'ISO-8859-2';
19 my $SWISH = '/usr/local/bin/swish-e';
20 my $INDEX = '/data/webpac/index/isis.index';
27 $self->tmpl_path($TEMPLATE_PATH);
29 'search' => 'show_search_form',
30 'results' => 'show_results_list',
31 # 'user' => 'show_user_detail',
32 'index' => 'show_index',
34 $self->start_mode('search');
35 $self->mode_param('rm');
37 $self->header_props(-charset=>$CHARSET);
40 sub show_search_form {
43 # Get the CGI.pm query object
44 my $q = $self->query();
46 my $tmpl = $self->load_tmpl('search.html');
47 my $html = $tmpl->output;
49 my $fif = new HTML::FillInForm;
51 return $fif->fill(scalarref => \$html, fobject => $q,
55 sub show_results_list {
58 my $q = $self->query();
60 my @swish_results; # results from swish
62 # load template for this page
64 my @s_arr; # all queries are located here
66 for(my $i = 1; $i <=10; $i++) {
68 return show_index($self, $i) if ($q->param("f".$i."_index"));
69 next if (! $q->param("f$i"));
70 next if (! $q->param("v$i"));
72 # re-write query from +/- to and/and not
74 my $search = $q->param("v$i");
75 while ($search =~ s/\s*("[^"]+")\s*/ /) {
81 foreach (split(/\s+/,$search)) {
82 if (m/^([+-])(\S+)/) {
83 $s.= ($s) ? "and " : "";
84 $s.="not " if ($1 eq "-");
91 push @s_arr,$q->param("f$i")."_swish=($s)";
94 my $tmpl = $self->load_tmpl('results.html');
97 my $sh = SWISH->connect('Fork',
100 #properties => [qw/god br nr/],
104 push @swish_results, {
105 nr => ($#swish_results + 2),
106 path => $hit->swishdocpath,
107 title => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }),
108 rank => $hit->swishrank };
110 # my @fields = $hit->field_names;
111 # print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
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");
177 my $index = new index_DBI();
179 if (! $index->check($field)) {
180 my $tmpl = $self->load_tmpl('no_index.html');
181 $tmpl->param('field',$field);
182 $html = $tmpl->output;
186 my @index_arr = $index->fetch($field,'item',$limit);
188 $html .= "show index of <i>$field</i>";
189 $html .= " for <i>$limit</i>" if ($limit);
191 while (my $row = shift @index_arr) {
192 $html .= "<br>".$row->{item}."\n";