/[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 51 by dpavlin, Sun Jun 1 15:33:08 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!  # FIXME 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            my @path_arr = $q->param('path');
71            my $full = $q->param('full');
72    
73          for(my $i = 1; $i <=10; $i++) {          for(my $i = 1; $i <=10; $i++) {
74    
75                  last if (! $q->param("f$i"));                  return show_index($self, $i) if ($q->param("f".$i."_index"));
76                    next if (! $q->param("f$i"));
77                  next if (! $q->param("v$i"));                  next if (! $q->param("v$i"));
78    
79                  # re-write query from +/- to and/and not                  # re-write query from +/- to and/and not
# Line 83  sub show_results_list { Line 94  sub show_results_list {
94                                  $s.="$_* ";                                  $s.="$_* ";
95                          }                          }
96                  }                  }
97                    $s =~ s/\*+/*/g;
98    
99                  push @s_arr,$q->param("f$i")."=($s)";                  push @s_arr,$q->param("f$i")."_swish=($s)";
100          }          }
101    
102          my $l2_map = Unicode::Map8->new($CHARSET) || die;          my $tmpl = $self->load_tmpl('results.html');
         my $us = Unicode::String->new();  
103    
104          # call swish          # call swish
105          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
106                  prog     => $SWISH,                  prog     => $SWISH,
107                  indexes  => $INDEX,                  indexes  => $INDEX,
108                  #properties  => [qw/god br nr/],                  properties  => [qw/swishdocpath swishrank swishtitle headline html/],
109                  results  => sub {                  results  => sub {
110                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
111    
                         $us->utf8($hit->swishtitle);  
   
112                          push @swish_results, {                          push @swish_results, {
113                                  nr => ($#swish_results + 2),                                  nr => ($#swish_results + 2),
114                                  path => $hit->swishdocpath,                                  path => $hit->swishdocpath,
115                                  title => $l2_map->to8($us->utf16),                                  headline => $from_utf8->convert($hit->headline),
116                                    html => back2html($from_utf8->convert($hit->html)),
117                                  rank => $hit->swishrank };                                  rank => $hit->swishrank };
118    
 #                       my @fields = $hit->field_names;  
 #                       print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields;  
119                  },                  },
120                  #startnum => 0,                  #startnum => 0,
121                  maxhits => $MAX_HITS,                  maxhits => $MAX_HITS
122          );          );
123    
124          die $SWISH::errstr unless $sh;          die $SWISH::errstr unless $sh;
125    
126          my $hits = $sh->query(join(" and ",@s_arr)) || 0;       # FIX: and/or          # construct swish query
127            my $sw_q = join(" and ",@s_arr);
128            if (@path_arr) {
129                    $sw_q .= "and (swishdocpath=\"";
130                    $sw_q .= join("\" or swishdocpath=\"",@path_arr);
131                    $sw_q .= "\")";
132                    $tmpl->param('full',1); # show full records
133            }
134    
135            my $hits = $sh->query($sw_q);
136    
137          $tmpl->param('hits',$hits);          $tmpl->param('hits',$hits);
138          $tmpl->param('search',join(" and ",@s_arr));          $tmpl->param('search',$sw_q);
139    
140            $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
141            $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
142    
143          # create a Pager object          # create a Pager object
144          my $pager = HTML::Pager->new(          my $pager = HTML::Pager->new(
# Line 161  sub show_results_list { Line 181  sub show_results_list {
181          return $html;          return $html;
182  }  }
183    
184    sub show_index {
185            my $self = shift;
186            my $i = shift;          # field number
187    
188            my $q = $self->query();
189    
190            my $field = $q->param("f$i");
191            my $limit = $q->param("v$i");
192    
193            my $html;
194    
195            my $index = new index_DBI();
196    
197            my $total = $index->check($field);
198            if (! $total) {
199                    my $tmpl = $self->load_tmpl('no_index.html');
200                    $tmpl->param('field',$field);
201                    $html = $tmpl->output;
202                    return $html;
203            }
204    
205            my $tmpl = $self->load_tmpl('index_res.html');
206            $tmpl->param('field',$field);
207            $tmpl->param('limit',$limit);
208            $tmpl->param('total',$total);
209    
210    # FIXME I should set offset and leave out limit from fetch!!
211    #       if (! $q->param("PAGER_offset") {
212    #               $q->param("Pager_offet)
213    #       }
214    
215            my $pager = HTML::Pager->new(
216                    query => $q,
217                    get_data_callback => sub {
218                            my ($offset, $rows) = @_;
219    
220                            my @result = $index->fetch($field,'item',$limit, $offset, $rows);
221                            return \@result;
222                    },
223                    rows => $total,
224                    page_size => $ON_PAGE,
225                    persist_vars => [
226                            'rm',
227                            "f$i", "v$i", "f".$i."_index",
228                            'offset',
229                            ],
230                    debug => 1,
231                    template => $tmpl,
232            );
233    
234            return $pager->output;
235    }
236    
237  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26