3 use base 'CGI::Application';
9 use Unicode::String qw(utf8 utf16);
10 require Unicode::Map8;
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 = '/data/swish/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'
30 $self->start_mode('search');
31 $self->mode_param('rm');
33 $self->header_props(-charset=>$CHARSET);
36 sub show_search_form {
39 # Get the CGI.pm query object
40 my $q = $self->query();
42 my $tmpl = $self->load_tmpl('search.html');
43 my $html = $tmpl->output;
45 my $fif = new HTML::FillInForm;
47 return $fif->fill(scalarref => \$html, fobject => $q,
51 sub show_results_list {
54 my $q = $self->query();
56 my @swish_results; # results from swish
58 # load template for this page
59 my $tmpl = $self->load_tmpl('results.html');
61 my @s_arr; # all queries are located here
63 for(my $i = 1; $i <=10; $i++) {
65 last if (! $q->param("f$i"));
66 next if (! $q->param("v$i"));
68 # re-write query from +/- to and/and not
70 my $search = $q->param("v$i");
71 while ($search =~ s/\s*("[^"]+")\s*/ /) {
77 foreach (split(/\s+/,$search)) {
78 if (m/^([+-])(\S+)/) {
79 $s.= ($s) ? "and " : "";
80 $s.="not " if ($1 eq "-");
87 push @s_arr,$q->param("f$i")."=($s)";
90 my $l2_map = Unicode::Map8->new($CHARSET) || die;
91 my $us = Unicode::String->new();
94 my $sh = SWISH->connect('Fork',
97 #properties => [qw/god br nr/],
101 $us->utf8($hit->swishtitle);
103 push @swish_results, {
104 nr => ($#swish_results + 2),
105 path => $hit->swishdocpath,
106 title => $l2_map->to8($us->utf16),
107 rank => $hit->swishrank };
109 # my @fields = $hit->field_names;
110 # print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;
113 maxhits => $MAX_HITS,
116 die $SWISH::errstr unless $sh;
118 my $hits = $sh->query(join(" and ",@s_arr)) || 0; # FIX: and/or
120 $tmpl->param('hits',$hits);
121 $tmpl->param('search',join(" and ",@s_arr));
123 # create a Pager object
124 my $pager = HTML::Pager->new(
125 # required parameters
127 get_data_callback => sub {
128 my ($offset, $rows) = @_;
131 for (my $i=0; $i<$rows; $i++) {
132 push @result, $swish_results[$offset+$i] if $swish_results[$offset+$i];
137 page_size => $ON_PAGE,
138 # some optional parameters
151 #cell_space_color => '#000000',
152 #cell_background_color => '#ffffff',
153 #nav_background_color => '#dddddd',
154 #javascript_presubmit => 'last_minute_javascript()',
159 my $html = $pager->output;