/[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 11 by dpavlin, Wed Jan 22 20:24:32 2003 UTC revision 53 by dpavlin, Sun Jun 1 18:49:49 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::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);  use Text::Iconv;
10  use DBI;  use DBI;
11    use Config::IniFiles;
12    
13  use lib '..';  use lib '..';
14  use index_DBI;  use index_DBI;
15    use back2html;
16    
17  # configuration options  # configuration options
18  # FIX: they really should go in configuration file!  # FIXME they really should go in configuration file!
19  my $TEMPLATE_PATH = '/data/webpac/template_html';  my $TEMPLATE_PATH = '/data/webpac/template_html';
20  my $CHARSET = 'ISO-8859-2';  my $CHARSET = 'ISO-8859-2';
21  my $SWISH = '/usr/local/bin/swish-e';  my $SWISH = '/usr/bin/swish-e';
22  my $INDEX = '/data/webpac/index/isis.index';  my $INDEX = '/data/webpac/index/isis.index';
23  my $MAX_HITS = 500;  my $MAX_HITS = 500;
24  my $ON_PAGE = 10;  my $ON_PAGE = 10;
25    
26    Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
27    
28    my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
29    
30    # read global.conf configuration
31    my $cfg_global = new Config::IniFiles( -file => '../global.conf' ) || die "can't open 'global.conf'";
32    
33    
34  sub setup {  sub setup {
35          my $self = shift;          my $self = shift;
# Line 63  sub show_results_list { Line 72  sub show_results_list {
72    
73          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
74    
75            my @path_arr = $q->param('path');
76            my $full = $q->param('full');
77    
78          for(my $i = 1; $i <=10; $i++) {          for(my $i = 1; $i <=10; $i++) {
79    
80                  return show_index($self, $i) if ($q->param("f".$i."_index"));                  return show_index($self, $i) if ($q->param("f".$i."_index"));
# Line 83  sub show_results_list { Line 95  sub show_results_list {
95                                  $s.= ($s) ? "and " : "";                                  $s.= ($s) ? "and " : "";
96                                  $s.="not " if ($1 eq "-");                                  $s.="not " if ($1 eq "-");
97                                  $s.="$2* ";                                  $s.="$2* ";
98                            } elsif (m/(and|or|not)/i) {
99                                    $s.="$_ ";
100                          } else {                          } else {
101                                  $s.="$_* ";                                  $s.="$_* ";
102                          }                          }
103                  }                  }
104                    $s =~ s/\*+/*/g;
105    
106                  push @s_arr,$q->param("f$i")."_swish=($s)";                  push @s_arr,$q->param("f$i")."_swish=($s)";
107          }          }
# Line 97  sub show_results_list { Line 112  sub show_results_list {
112          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
113                  prog     => $SWISH,                  prog     => $SWISH,
114                  indexes  => $INDEX,                  indexes  => $INDEX,
115                  #properties  => [qw/god br nr/],                  properties  => [qw/swishdocpath swishrank swishtitle headline html/],
116                  results  => sub {                  results  => sub {
117                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
118    
119                          push @swish_results, {                          push @swish_results, {
120                                  nr => ($#swish_results + 2),                                  nr => ($#swish_results + 2),
121                                  path => $hit->swishdocpath,                                  path => $hit->swishdocpath,
122                                  title => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }),                                  headline => $from_utf8->convert($hit->headline),
123                                    html => back2html($from_utf8->convert($hit->html)),
124                                  rank => $hit->swishrank };                                  rank => $hit->swishrank };
125    
 #                       my @fields = $hit->field_names;  
 #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
126                  },                  },
127                  #startnum => 0,                  #startnum => 0,
128                  maxhits => $MAX_HITS,                  maxhits => $MAX_HITS
129          );          );
130    
131          die $SWISH::errstr unless $sh;          die $SWISH::errstr unless $sh;
132    
133          my $hits = $sh->query(join(" and ",@s_arr)) || 0;       # FIX: and/or          # construct swish query
134            my $sw_q = join(" and ",@s_arr);
135            if (@path_arr) {
136                    $sw_q .= "and (swishdocpath=\"";
137                    $sw_q .= join("\" or swishdocpath=\"",@path_arr);
138                    $sw_q .= "\")";
139                    $tmpl->param('full',1); # show full records
140            }
141    
142            my $hits = $sh->query($sw_q);
143    
144          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
145          $tmpl->param('search',join(" and ",@s_arr));          $tmpl->param('search',$sw_q);
146    
147            $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
148            $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
149    
150          # create a Pager object          # create a Pager object
151          my $pager = HTML::Pager->new(          my $pager = HTML::Pager->new(
# Line 171  sub show_index { Line 197  sub show_index {
197          my $field = $q->param("f$i");          my $field = $q->param("f$i");
198          my $limit = $q->param("v$i");          my $limit = $q->param("v$i");
199    
   
200          my $html;          my $html;
201    
202          my $index = new index_DBI();          my $index = new index_DBI(
203                    $cfg_global->val('global', 'dbi_dbd'),
204                    $cfg_global->val('global', 'dbi_dsn'),
205                    $cfg_global->val('global', 'dbi_user'),
206                    $cfg_global->val('global', 'dbi_passwd') || ''
207            );
208    
209          if (! $index->check($field)) {          my $total = $index->check($field);
210            if (! $total) {
211                  my $tmpl = $self->load_tmpl('no_index.html');                  my $tmpl = $self->load_tmpl('no_index.html');
212                  $tmpl->param('field',$field);                  $tmpl->param('field',$field);
213                  $html = $tmpl->output;                  $html = $tmpl->output;
214                  return $html;                  return $html;
215          }          }
216    
217          my @index_arr = $index->fetch($field,'item',$limit);          my $tmpl = $self->load_tmpl('index_res.html');
218            $tmpl->param('field',$field);
219            $tmpl->param('limit',$limit);
220            $tmpl->param('total',$total);
221    
222    # FIXME I should set offset and leave out limit from fetch!!
223    #       if (! $q->param("PAGER_offset") {
224    #               $q->param("Pager_offet)
225    #       }
226    
227          $html .= "show index of <i>$field</i>";          my $pager = HTML::Pager->new(
228          $html .= " for <i>$limit</i>" if ($limit);                  query => $q,
229                    get_data_callback => sub {
230                            my ($offset, $rows) = @_;
231    
232          while (my $row = shift @index_arr) {                          my @result = $index->fetch($field,'item',$limit, $offset, $rows);
233                  $html .= "<br>".$row->{item}."\n";                          return \@result;
234          }                  },
235                    rows => $total,
236                    page_size => $ON_PAGE,
237                    persist_vars => [
238                            'rm',
239                            "f$i", "v$i", "f".$i."_index",
240                            'offset',
241                            ],
242                    debug => 1,
243                    template => $tmpl,
244            );
245    
246          return $html;          return $pager->output;
247  }  }
248    
249  1;  1;

Legend:
Removed from v.11  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26