/[webpac]/branches/tehnika/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 /branches/tehnika/WebPac.pm

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

revision 10 by dpavlin, Thu Jan 16 17:35:54 2003 UTC revision 35 by dpavlin, Sun Feb 23 15:47:40 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    
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 = '/usr/local/bin/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 84  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")."_swish=($s)";                  push @s_arr,$q->param("f$i")."_swish=($s)";
97          }          }
# Line 94  sub show_results_list { Line 102  sub show_results_list {
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    
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 => to_utf8({ -string => $hit->swishtitle, -charset => $CHARSET }),  #                               headline => $from_utf8->convert($hit->headline),
113    #                               html => back2html($from_utf8->convert($hit->html)),
114                                    headline => $hit->headline,
115                                    html => back2html($hit->html),
116                                  rank => $hit->swishrank };                                  rank => $hit->swishrank };
117    
 #                       my @fields = $hit->field_names;  
 #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
118                  },                  },
119                  #startnum => 0,                  #startnum => 0,
120                  maxhits => $MAX_HITS,                  maxhits => $MAX_HITS,
# Line 165  sub show_index { Line 174  sub show_index {
174    
175          my $q = $self->query();          my $q = $self->query();
176    
177            my $field = $q->param("f$i");
178            my $limit = $q->param("v$i");
179    
180          my $html;          my $html;
181    
182          $html .= "show index of ".$q->param("f$i")." for ".$q->param("v$i");          my $index = new index_DBI();
183    
184            my $total = $index->check($field);
185            if (! $total) {
186                    my $tmpl = $self->load_tmpl('no_index.html');
187                    $tmpl->param('field',$field);
188                    $html = $tmpl->output;
189                    return $html;
190            }
191    
192          return $html;          my $tmpl = $self->load_tmpl('index_res.html');
193            $tmpl->param('field',$field);
194            $tmpl->param('limit',$limit);
195            $tmpl->param('total',$total);
196    
197    # FIX: I should set offset and leave out limit from fetch!!
198    #       if (! $q->param("PAGER_offset") {
199    #               $q->param("Pager_offet)
200    #       }
201    
202            my $pager = HTML::Pager->new(
203                    query => $q,
204                    get_data_callback => sub {
205                            my ($offset, $rows) = @_;
206    
207                            my @result = $index->fetch($field,'item',$limit, $offset, $rows);
208                            return \@result;
209                    },
210                    rows => $total,
211                    page_size => $ON_PAGE,
212                    persist_vars => [
213                            'rm',
214                            "f$i", "v$i", "f".$i."_index",
215                            'offset',
216                            ],
217                    debug => 1,
218                    template => $tmpl,
219            );
220    
221            return $pager->output;
222  }  }
223    
224  1;  1;

Legend:
Removed from v.10  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26