--- trunk/html/swish.cgi 2003/03/24 09:04:57 29
+++ trunk/html/swish.cgi 2004/04/06 19:21:07 73
@@ -3,10 +3,14 @@
use strict;
use CGI qw/:standard -no_xhtml/;
use CGI::Carp qw(fatalsToBrowser);
-use SWISH;
+use SWISH::API;
use XML::Simple;
use Lingua::Spelling::Alternative;
use Text::Iconv;
+use Data::Pageset;
+
+# for pager
+my $pages_per_set = 20;
Text::Iconv->raise_error(0); # Conversion errors raise exceptions
my $config=XMLin(undef,
@@ -16,6 +20,7 @@
my $from_utf8 = Text::Iconv->new('UTF8', $config->{charset});
sub x {
+ return if (! defined $_[0]);
return $from_utf8->convert($_[0]);
}
@@ -31,22 +36,29 @@
return $out;
}
-my $spelling_alt;
+my @spellings;
# FIX: doesn't work very well
if ($config->{findaffix}) {
- $spelling_alt = new Lingua::Spelling::Alternative;
- $spelling_alt->load_findaffix(x($config->{findaffix}));
+ foreach my $findaffix (split(/[, ]+/,x($config->{findaffix}))) {
+ my $spelling_alt = new Lingua::Spelling::Alternative;
+ $spelling_alt->load_findaffix($findaffix);
+ push @spellings,$spelling_alt;
+ }
}
if ($config->{affix}) {
- $spelling_alt = new Lingua::Spelling::Alternative;
- $spelling_alt->load_affix(x($config->{affix}));
+ foreach my $affix (split(/[, ]+/,x($config->{affix}))) {
+ my $spelling_alt = new Lingua::Spelling::Alternative;
+ $spelling_alt->load_affix($affix);
+ push @spellings,$spelling_alt;
+ }
}
my $hits=0;
-my $max_hits=x($config->{max_hits});
+my $max_hits=param('max_hits') || x($config->{max_hits});
my %labels;
foreach (@{$config->{labels}->{label}}) {
+ next if (! $_->{value}); # skip unlimited (0)
$labels{$_->{value}} = x($_->{content});
}
@@ -54,10 +66,14 @@
my %path_label;
my @path_name;
foreach (@{$config->{paths}->{path}}) {
+
+print STDERR "##: $_->{limit}",x($_->{content}),"\n";
push @path_name,x($_->{limit});
$path_label{$_->{limit}} = x($_->{content});
}
+my @properties = split(/\s+/,x($config->{properties})) if ($config->{properties});
+
if ($config->{charset}) {
print header(-charset=>x($config->{charset}));
} else {
@@ -69,7 +85,8 @@
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 (@spellings);
+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);
@@ -89,22 +106,32 @@
$search =~ s/^\s+//;
$search =~ s/\s+$//;
+ my %words;
+
foreach (split(/\s+/,$search)) {
if (m/^([+-])(\S+)/) {
$s.= ($s) ? "and " : "";
$s.="not " if ($1 eq "-");
- if ($spelling_alt && !param('no_affix')) {
+ if (@spellings && !param('no_affix')) {
my $w = $2; $w =~ s/[\*\s]+//g;
$w =~ s/^(['"]*)([^'"]+)(['"]*)/$2/;
- $s.="$1(".join("* or ",$spelling_alt->alternatives($w))."*)$3 ";
+ my $or="";
+ foreach my $spelling_alt (@spellings) {
+ $s.="$or$1(".join("* or ",$spelling_alt->alternatives($w))."*)$3 ";
+ $or = "or ";
+ }
} else {
$s.="$2* ";
}
} else {
- if ($spelling_alt && !param('no_affix')) {
+ if (@spellings && !param('no_affix')) {
my $w = $_; $w =~ s/[\*\s]+//g;
#$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) ";
- $s.="(".join("* or ",$spelling_alt->alternatives($w))."*) ";
+ my $or="";
+ foreach my $spelling_alt (@spellings) {
+ $s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) ";
+ $or = "or ";
+ }
} else {
$s.="$_* ";
}
@@ -117,49 +144,172 @@
$s=~s/\*\*+/*/g;
# limit to some path
- $s = "swishdocpath=(\"$path\") and $s" if ($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";
- my $sh = SWISH->connect('Fork',
- prog => x($config->{prog}),
- indexes => x($config->{index}),
- results => sub {
- my ($sh,$hit) = @_;
+ # output start of table
+ print qq{
+
+ }; + my $tr_post = qq{ + |
+Pages: $nav_html + |