/[swish]/trunk/html/swish.cgi
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/html/swish.cgi

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

revision 16 by dpavlin, Sun Mar 16 21:44:42 2003 UTC revision 21 by dpavlin, Tue Mar 18 20:20:11 2003 UTC
# Line 8  use XML::Simple; Line 8  use XML::Simple;
8  use Lingua::Spelling::Alternative;  use Lingua::Spelling::Alternative;
9  use Text::Iconv;  use Text::Iconv;
10    
 # output charset  
 my $CHARSET='ISO-8859-2';  
   
11  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
 my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);  
   
12  my $config=XMLin(undef,  my $config=XMLin(undef,
13  #               keyattr => { label => "value" },  #               keyattr => { label => "value" },
14                  forcecontent => 0,                  forcecontent => 0,
15          );          );
16    
17    my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});
18    sub x {
19            return $from_utf8->convert($_[0]);
20    }
21    
22  use Data::Dumper;  use Data::Dumper;
23  #print Dumper($config);  #print Dumper($config);
24    
# Line 26  my $spelling_alt; Line 26  my $spelling_alt;
26  # FIX: doesn't work very well  # FIX: doesn't work very well
27  if ($config->{findaffix}) {  if ($config->{findaffix}) {
28          $spelling_alt = new Lingua::Spelling::Alternative;          $spelling_alt = new Lingua::Spelling::Alternative;
29          $spelling_alt->load_findaffix($config->{affix});          $spelling_alt->load_findaffix(x($config->{findaffix}));
30  }  }
31  if ($config->{affix}) {  if ($config->{affix}) {
32          $spelling_alt = new Lingua::Spelling::Alternative;          $spelling_alt = new Lingua::Spelling::Alternative;
33          $spelling_alt->load_affix($config->{affix});          $spelling_alt->load_affix(x($config->{affix}));
34  }  }
35    
36  my $hits=0;  my $hits=0;
37  my $max_hits=$config->{max_hits};  my $max_hits=x($config->{max_hits});
38    
39  my %labels;  my %labels;
40  foreach (@{$config->{labels}->{label}}) {  foreach (@{$config->{labels}->{label}}) {
41          $labels{$_->{value}} = $from_utf8->convert($_->{content});          $labels{$_->{value}} = x($_->{content});
42  }  }
43    
44  if ($config->{charset}) {  if ($config->{charset}) {
45          print header(-charset=>$config->{charset});          print header(-charset=>x($config->{charset}));
46  } else {  } else {
47          print header;          print header;
48  }  }
49  print start_html(-title=>$config->{title}),start_form;  print start_html(-title=>x($config->{title})),start_form;
50  print $config->{text}->{search};  print x($config->{text}->{search});
51  print popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits);  print popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits);
52  print $config->{text}->{documents};  print x($config->{text}->{documents});
53  print textfield('search');  print textfield('search');
54  print submit(-value=> $config->{text}->{submit});  print submit(-value=> x($config->{text}->{submit}));
55  print checkbox(-name=>'no_affix', -checked=>0, -label=>$config->{text}->{no_spell}) if ($spelling_alt);  print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);
56  print end_form,hr;  print end_form,hr;
57    
58  if (param('search')) {  if (param('search')) {
# Line 95  if (param('search')) { Line 95  if (param('search')) {
95          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;          $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
96          $s=~s/\*\*+/*/g;          $s=~s/\*\*+/*/g;
97    
98            my @properties = split(/\s+/,x($config->{properties}));
99    
100          my $sh = SWISH->connect('Fork',          my $sh = SWISH->connect('Fork',
101                  prog     => $config->{prog},                  prog     => x($config->{prog}),
102                  indexes  => $config->{index},                  indexes  => x($config->{index}),
103  #               properties  => [qw/god br nr/],                  properties  => \@properties,
104                  results  => sub {                  results  => sub {
105                          my ($sh,$hit) = @_;                          my ($sh,$hit) = @_;
106    
107                          printf ("<a href=\"%s\">%s</a> [%s]<br>\n","http://".virtual_host().$config->{url}.$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);                          my $hit_fmt = x($config->{hit}) ||
108                                    "<a href=\"%s\">%s</a> [%s]<br>\n";
109    
110                            if ($config->{url}) {
111                                    printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);
112                            } else {
113                                    printf ($hit_fmt ,$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank, map($hit->$_, @properties) );
114    
115                            }
116    
117  #                       print $_[1]->as_string,"<br>\n";  #                       print $_[1]->as_string,"<br>\n";
118  #                       my @fields = $hit->field_names;  #                       my @fields = $hit->field_names;
# Line 118  if (param('search')) { Line 128  if (param('search')) {
128    
129          if ($hits > 0) {          if ($hits > 0) {
130                  print p,hr;                  print p,hr;
131                  printf ($config->{text}->{hits},$hits,param('max_hits') || $max_hits,$s);                  printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s);
132          } else {          } else {
133                  print p;                  print p;
134                  printf ($config->{text}->{no_hits},$s,$sh->errstr);                  printf (x($config->{text}->{no_hits}),$s,$sh->errstr);
135          }          }
136  } else {  } else {
137          print p($config->{text}->{footer});          print p(x($config->{text}->{footer}));
138  }  }

Legend:
Removed from v.16  
changed lines
  Added in v.21

  ViewVC Help
Powered by ViewVC 1.1.26