/[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 41 by dpavlin, Sat Mar 15 21:34:36 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 Text::Iconv;
10  require Unicode::Map8;  use DBI;
11    
12    use lib '..';
13    use index_DBI;
14    use back2html;
15    
16  # configuration options  # configuration options
17  # FIX: they really should go in configuration file!  # FIX: they really should go in configuration file!
18  my $TEMPLATE_PATH = '/data/webpac/template_html';  my $TEMPLATE_PATH = '/data/webpac/template_html';
19  my $CHARSET = 'ISO-8859-2';  my $CHARSET = 'ISO-8859-2';
20  my $SWISH = '/data/swish/swish-e';  my $SWISH = '/usr/bin/swish-e';
21  my $INDEX = '/data/webpac/index/isis.index';  my $INDEX = '/data/webpac/index/isis.index';
22  my $MAX_HITS = 500;  my $MAX_HITS = 500;
23  my $ON_PAGE = 10;  my $ON_PAGE = 10;
24    
25    Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
26    
27    my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
28    
29  sub setup {  sub setup {
30          my $self = shift;          my $self = shift;
# Line 25  sub setup { Line 32  sub setup {
32          $self->run_modes(          $self->run_modes(
33                  'search' => 'show_search_form',                  'search' => 'show_search_form',
34                  'results' => 'show_results_list',                  'results' => 'show_results_list',
35  #               'user' => 'show_user_detail'  #               'user' => 'show_user_detail',
36                    'index' => 'show_index',
37          );          );
38          $self->start_mode('search');          $self->start_mode('search');
39          $self->mode_param('rm');          $self->mode_param('rm');
# Line 56  sub show_results_list { Line 64  sub show_results_list {
64          my @swish_results;      # results from swish          my @swish_results;      # results from swish
65    
66          # load template for this page          # load template for this page
         my $tmpl = $self->load_tmpl('results.html');  
67    
68          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
69    
70          for(my $i = 1; $i <=10; $i++) {          for(my $i = 1; $i <=10; $i++) {
71    
72                  last if (! $q->param("f$i"));                  return show_index($self, $i) if ($q->param("f".$i."_index"));
73                    next if (! $q->param("f$i"));
74                  next if (! $q->param("v$i"));                  next if (! $q->param("v$i"));
75    
76                  # re-write query from +/- to and/and not                  # re-write query from +/- to and/and not
# Line 83  sub show_results_list { Line 91  sub show_results_list {
91                                  $s.="$_* ";                                  $s.="$_* ";
92                          }                          }
93                  }                  }
94                    $s =~ s/\*+/*/g;
95    
96                  push @s_arr,$q->param("f$i")."=($s)";                  push @s_arr,$q->param("f$i")."_swish=($s)";
97          }          }
98    
99          my $l2_map = Unicode::Map8->new($CHARSET) || die;          my $tmpl = $self->load_tmpl('results.html');
         my $us = Unicode::String->new();  
100    
101          # call swish          # call swish
102          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
103                  prog     => $SWISH,                  prog     => $SWISH,
104                  indexes  => $INDEX,                  indexes  => $INDEX,
105                  #properties  => [qw/god br nr/],                  properties  => [qw/swishdocpath swishrank swishtitle headline html/],
106                  results  => sub {                  results  => sub {
107                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
108    
                         $us->utf8($hit->swishtitle);  
   
109                          push @swish_results, {                          push @swish_results, {
110                                  nr => ($#swish_results + 2),                                  nr => ($#swish_results + 2),
111                                  path => $hit->swishdocpath,                                  path => $hit->swishdocpath,
112                                  title => $l2_map->to8($us->utf16),                                  headline => $from_utf8->convert($hit->headline),
113                                    html => back2html($from_utf8->convert($hit->html)),
114                                  rank => $hit->swishrank };                                  rank => $hit->swishrank };
115    
 #                       my @fields = $hit->field_names;  
 #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
116                  },                  },
117                  #startnum => 0,                  #startnum => 0,
118                  maxhits => $MAX_HITS,                  maxhits => $MAX_HITS,
# Line 161  sub show_results_list { Line 166  sub show_results_list {
166          return $html;          return $html;
167  }  }
168    
169    sub show_index {
170            my $self = shift;
171            my $i = shift;          # field number
172    
173            my $q = $self->query();
174    
175            my $field = $q->param("f$i");
176            my $limit = $q->param("v$i");
177    
178            my $html;
179    
180            my $index = new index_DBI();
181    
182            my $total = $index->check($field);
183            if (! $total) {
184                    my $tmpl = $self->load_tmpl('no_index.html');
185                    $tmpl->param('field',$field);
186                    $html = $tmpl->output;
187                    return $html;
188            }
189    
190            my $tmpl = $self->load_tmpl('index_res.html');
191            $tmpl->param('field',$field);
192            $tmpl->param('limit',$limit);
193            $tmpl->param('total',$total);
194    
195    # FIX: I should set offset and leave out limit from fetch!!
196    #       if (! $q->param("PAGER_offset") {
197    #               $q->param("Pager_offet)
198    #       }
199    
200            my $pager = HTML::Pager->new(
201                    query => $q,
202                    get_data_callback => sub {
203                            my ($offset, $rows) = @_;
204    
205                            my @result = $index->fetch($field,'item',$limit, $offset, $rows);
206                            return \@result;
207                    },
208                    rows => $total,
209                    page_size => $ON_PAGE,
210                    persist_vars => [
211                            'rm',
212                            "f$i", "v$i", "f".$i."_index",
213                            'offset',
214                            ],
215                    debug => 1,
216                    template => $tmpl,
217            );
218    
219            return $pager->output;
220    }
221    
222  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26