/[webpac]/trunk/WebPac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/WebPac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 7 by dpavlin, Sat Jan 11 16:44:03 2003 UTC revision 12 by dpavlin, Wed Jan 22 22:27:19 2003 UTC
# Line 6  use strict; Line 6  use strict;
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 Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
10  require Unicode::Map8;  use DBI;
11    
12    use lib '..';
13    use index_DBI;
14    
15  # configuration options  # configuration options
16  # FIX: they really should go in configuration file!  # FIX: they really should go in configuration file!
17  my $TEMPLATE_PATH = '/data/webpac/template_html';  my $TEMPLATE_PATH = '/data/webpac/template_html';
18  my $CHARSET = 'ISO-8859-2';  my $CHARSET = 'ISO-8859-2';
19  my $SWISH = '/data/swish/swish-e';  my $SWISH = '/usr/local/bin/swish-e';
20  my $INDEX = '/data/webpac/index/isis.index';  my $INDEX = '/data/webpac/index/isis.index';
21  my $MAX_HITS = 500;  my $MAX_HITS = 500;
22  my $ON_PAGE = 10;  my $ON_PAGE = 10;
# Line 25  sub setup { Line 28  sub setup {
28          $self->run_modes(          $self->run_modes(
29                  'search' => 'show_search_form',                  'search' => 'show_search_form',
30                  'results' => 'show_results_list',                  'results' => 'show_results_list',
31  #               'user' => 'show_user_detail'  #               'user' => 'show_user_detail',
32                    'index' => 'show_index',
33          );          );
34          $self->start_mode('search');          $self->start_mode('search');
35          $self->mode_param('rm');          $self->mode_param('rm');
# Line 56  sub show_results_list { Line 60  sub show_results_list {
60          my @swish_results;      # results from swish          my @swish_results;      # results from swish
61    
62          # load template for this page          # load template for this page
         my $tmpl = $self->load_tmpl('results.html');  
63    
64          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
65    
66          for(my $i = 1; $i <=10; $i++) {          for(my $i = 1; $i <=10; $i++) {
67    
68                  last if (! $q->param("f$i"));                  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"));                  next if (! $q->param("v$i"));
71    
72                  # re-write query from +/- to and/and not                  # re-write query from +/- to and/and not
# Line 84  sub show_results_list { Line 88  sub show_results_list {
88                          }                          }
89                  }                  }
90    
91                  push @s_arr,$q->param("f$i")."=($s)";                  push @s_arr,$q->param("f$i")."_swish=($s)";
92          }          }
93    
94          my $l2_map = Unicode::Map8->new($CHARSET) || die;          my $tmpl = $self->load_tmpl('results.html');
         my $us = Unicode::String->new();  
95    
96          # call swish          # call swish
97          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
# Line 98  sub show_results_list { Line 101  sub show_results_list {
101                  results  => sub {                  results  => sub {
102                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
103    
                         $us->utf8($hit->swishtitle);  
   
104                          push @swish_results, {                          push @swish_results, {
105                                  nr => ($#swish_results + 2),                                  nr => ($#swish_results + 2),
106                                  path => $hit->swishdocpath,                                  path => $hit->swishdocpath,
107                                  title => $l2_map->to8($us->utf16),                                  title => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }),
108                                  rank => $hit->swishrank };                                  rank => $hit->swishrank };
109    
110  #                       my @fields = $hit->field_names;  #                       my @fields = $hit->field_names;
# Line 161  sub show_results_list { Line 162  sub show_results_list {
162          return $html;          return $html;
163  }  }
164    
165    sub show_index {
166            my $self = shift;
167            my $i = shift;          # field number
168    
169            my $q = $self->query();
170    
171            my $field = $q->param("f$i");
172            my $limit = $q->param("v$i");
173    
174            my $html;
175    
176            my $index = new index_DBI();
177    
178            my $total = $index->check($field);
179            if (! $total) {
180                    my $tmpl = $self->load_tmpl('no_index.html');
181                    $tmpl->param('field',$field);
182                    $html = $tmpl->output;
183                    return $html;
184            }
185    
186            my $tmpl = $self->load_tmpl('index_res.html');
187            $tmpl->param('field',$field);
188            $tmpl->param('limit',$limit);
189            $tmpl->param('total',$total);
190    
191            my $pager = HTML::Pager->new(
192                    query => $q,
193                    get_data_callback => sub {
194                            my ($offset, $rows) = @_;
195    
196                            my @result = $index->fetch($field,'item',$limit, $offset, $rows);
197                            return \@result;
198                    },
199                    rows => $total,
200                    page_size => $ON_PAGE,
201                    persist_vars => [
202                            'rm',
203                            "f$i", "v$i", "f".$i."_index",
204                            'offset',
205                            ],
206                    debug => 1,
207                    template => $tmpl,
208            );
209    
210            return $pager->output;
211    }
212    
213  1;  1;

Legend:
Removed from v.7  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26