3 use base 'CGI::Application';
9 use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
12 # configuration options
13 # FIX: they really should go in configuration file!
14 my $TEMPLATE_PATH = '/data/webpac/template_html';
15 my $CHARSET = 'ISO-8859-2';
16 my $SWISH = '/usr/local/bin/swish-e';
17 my $INDEX = '/data/webpac/index/isis.index';
24 $self->tmpl_path($TEMPLATE_PATH);
26 'search' => 'show_search_form',
27 'results' => 'show_results_list',
28 # 'user' => 'show_user_detail',
29 'index' => 'show_index',
31 $self->start_mode('search');
32 $self->mode_param('rm');
34 $self->header_props(-charset=>$CHARSET);
37 sub show_search_form {
40 # Get the CGI.pm query object
41 my $q = $self->query();
43 my $tmpl = $self->load_tmpl('search.html');
44 my $html = $tmpl->output;
46 my $fif = new HTML::FillInForm;
48 return $fif->fill(scalarref => \$html, fobject => $q,
52 sub show_results_list {
55 my $q = $self->query();
57 my @swish_results; # results from swish
59 # load template for this page
61 my @s_arr; # all queries are located here
63 for(my $i = 1; $i <=10; $i++) {
65 return show_index($self, $i) if ($q->param("f".$i."_index"));
66 next if (! $q->param("f$i"));
67 next if (! $q->param("v$i"));
69 # re-write query from +/- to and/and not
71 my $search = $q->param("v$i");
72 while ($search =~ s/\s*("[^"]+")\s*/ /) {
78 foreach (split(/\s+/,$search)) {
79 if (m/^([+-])(\S+)/) {
80 $s.= ($s) ? "and " : "";
81 $s.="not " if ($1 eq "-");
88 push @s_arr,$q->param("f$i")."_swish=($s)";
91 my $tmpl = $self->load_tmpl('results.html');
94 my $sh = SWISH->connect('Fork',
97 #properties => [qw/god br nr/],
101 push @swish_results, {
102 nr => ($#swish_results + 2),
103 path => $hit->swishdocpath,
104 title => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }),
105 rank => $hit->swishrank };
107 # my @fields = $hit->field_names;
108 # print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
111 maxhits => $MAX_HITS,
114 die $SWISH::errstr unless $sh;
116 my $hits = $sh->query(join(" and ",@s_arr)) || 0; # FIX: and/or
118 $tmpl->param('hits',$hits);
119 $tmpl->param('search',join(" and ",@s_arr));
121 # create a Pager object
122 my $pager = HTML::Pager->new(
123 # required parameters
125 get_data_callback => sub {
126 my ($offset, $rows) = @_;
129 for (my $i=0; $i<$rows; $i++) {
130 push @result, $swish_results[$offset+$i] if $swish_results[$offset+$i];
135 page_size => $ON_PAGE,
136 # some optional parameters
149 #cell_space_color => '#000000',
150 #cell_background_color => '#ffffff',
151 #nav_background_color => '#dddddd',
152 #javascript_presubmit => 'last_minute_javascript()',
157 my $html = $pager->output;
164 my $i = shift; # field number
166 my $q = $self->query();
170 $html .= "show index of ".$q->param("f$i")." for ".$q->param("v$i");