--- trunk/html/swish.cgi 2003/03/16 21:45:23 17
+++ trunk/html/swish.cgi 2003/03/16 21:59:10 18
@@ -8,17 +8,17 @@
use Lingua::Spelling::Alternative;
use Text::Iconv;
-# output charset
-my $CHARSET='ISO-8859-2';
-
Text::Iconv->raise_error(0); # Conversion errors raise exceptions
-my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
-
my $config=XMLin(undef,
# keyattr => { label => "value" },
forcecontent => 0,
);
+my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});
+sub x {
+ return $from_utf8->convert($_[0]);
+}
+
use Data::Dumper;
#print Dumper($config);
@@ -26,33 +26,33 @@
# FIX: doesn't work very well
if ($config->{findaffix}) {
$spelling_alt = new Lingua::Spelling::Alternative;
- $spelling_alt->load_findaffix($config->{affix});
+ $spelling_alt->load_findaffix(x($config->{findaffix}));
}
if ($config->{affix}) {
$spelling_alt = new Lingua::Spelling::Alternative;
- $spelling_alt->load_affix($config->{affix});
+ $spelling_alt->load_affix(x($config->{affix}));
}
my $hits=0;
-my $max_hits=$config->{max_hits};
+my $max_hits=x($config->{max_hits});
my %labels;
foreach (@{$config->{labels}->{label}}) {
- $labels{$_->{value}} = $from_utf8->convert($_->{content});
+ $labels{$_->{value}} = x($_->{content});
}
if ($config->{charset}) {
- print header(-charset=>$config->{charset});
+ print header(-charset=>x($config->{charset}));
} else {
print header;
}
-print start_html(-title=>$config->{title}),start_form;
-print $config->{text}->{search};
+print start_html(-title=>x($config->{title})),start_form;
+print x($config->{text}->{search});
print popup_menu(-name=>'max_hits',-values=>[ sort keys %labels ],-labels=>\%labels,-default=>$max_hits);
-print $config->{text}->{documents};
+print x($config->{text}->{documents});
print textfield('search');
-print submit(-value=> $config->{text}->{submit});
-print checkbox(-name=>'no_affix', -checked=>0, -label=>$config->{text}->{no_spell}) if ($spelling_alt);
+print submit(-value=> x($config->{text}->{submit}));
+print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);
print end_form,hr;
if (param('search')) {
@@ -96,13 +96,18 @@
$s=~s/\*\*+/*/g;
my $sh = SWISH->connect('Fork',
- prog => $config->{prog},
- indexes => $config->{index},
+ prog => x($config->{prog}),
+ indexes => x($config->{index}),
# properties => [qw/god br nr/],
results => sub {
my ($sh,$hit) = @_;
- printf ("%s [%s]
\n","http://".virtual_host().$config->{url}.$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);
+ if ($config->{url}) {
+ printf ("%s [%s]
\n","http://".virtual_host().x($config->{url}).$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);
+ } else {
+ printf ("%s [%s]
\n",$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);
+
+ }
# print $_[1]->as_string,"
\n";
# my @fields = $hit->field_names;
@@ -118,11 +123,11 @@
if ($hits > 0) {
print p,hr;
- printf ($config->{text}->{hits},$hits,param('max_hits') || $max_hits,$s);
+ printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s);
} else {
print p;
- printf ($config->{text}->{no_hits},$s,$sh->errstr);
+ printf (x($config->{text}->{no_hits}),$s,$sh->errstr);
}
} else {
- print p($config->{text}->{footer});
+ print p(x($config->{text}->{footer}));
}