--- trunk/html/swish.cgi 2003/03/18 20:24:57 22
+++ trunk/html/swish.cgi 2003/04/30 12:40:09 32
@@ -19,8 +19,17 @@
return $from_utf8->convert($_[0]);
}
-use Data::Dumper;
-#print Dumper($config);
+# Escape <, >, & and ", and to produce valid XML
+my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
+my $escape_re = join '|' => keys %escape;
+sub e {
+ my $out;
+ foreach my $v (@_) {
+ $v =~ s/($escape_re)/$escape{$1}/g;
+ $out .= $v;
+ }
+ return $out;
+}
my $spelling_alt;
# FIX: doesn't work very well
@@ -41,6 +50,16 @@
$labels{$_->{value}} = x($_->{content});
}
+my $path = param('path'); # limit to this path
+my %path_label;
+my @path_name;
+foreach (@{$config->{paths}->{path}}) {
+ push @path_name,x($_->{limit});
+ $path_label{$_->{limit}} = x($_->{content});
+}
+
+my @properties = split(/\s+/,x($config->{properties}));
+
if ($config->{charset}) {
print header(-charset=>x($config->{charset}));
} else {
@@ -52,7 +71,12 @@
print x($config->{text}->{documents});
print textfield('search');
print submit(-value=> x($config->{text}->{submit}));
-print checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);
+print br,checkbox(-name=>'no_affix', -checked=>0, -label=>x($config->{text}->{no_spell})) if ($spelling_alt);
+print checkbox(-name=>'no_properties', -checked=>0, -label=>($config->{text}->{no_properties})) if (@properties);
+if (@path_name) {
+ print br,x($config->{text}->{limit});
+ print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path);
+}
print end_form,hr;
if (param('search')) {
@@ -95,10 +119,20 @@
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/;
$s=~s/\*\*+/*/g;
+ # limit to some path
+ $s = "swishdocpath=(\"$path\") and $s" if ($path);
+
my %params; # optional parametars for swish
- my @properties = split(/\s+/,x($config->{properties}));
- $params{properties} = \@properties if (@properties);
+ # default format for output
+ my $hit_fmt = "%s [%s]
\n";
+
+ if (@properties) {
+ $hit_fmt = x($config->{hit}) if (! param('no_properties'));
+ $params{properties} = \@properties if (@properties);
+ } else {
+ $hit_fmt = x($config->{hit}) if (x($config->{hit}));
+ }
my $sh = SWISH->connect('Fork',
prog => x($config->{prog}),
@@ -106,13 +140,10 @@
results => sub {
my ($sh,$hit) = @_;
- my $hit_fmt = x($config->{hit}) ||
- "%s [%s]
\n";
-
if ($config->{url}) {
- printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank);
+ printf ($hit_fmt ,"http://".virtual_host().x($config->{url}).$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties));
} else {
- printf ($hit_fmt ,$hit->swishdocpath,$hit->swishtitle || 'untitled',$hit->swishrank, map($hit->$_, @properties) );
+ printf ($hit_fmt ,$hit->swishdocpath,e($hit->swishtitle) || 'untitled',$hit->swishrank, map($hit->$_, @properties) );
}