19 |
return $from_utf8->convert($_[0]); |
return $from_utf8->convert($_[0]); |
20 |
} |
} |
21 |
|
|
22 |
use Data::Dumper; |
# Escape <, >, & and ", and to produce valid XML |
23 |
#print Dumper($config); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
24 |
|
my $escape_re = join '|' => keys %escape; |
25 |
|
sub e { |
26 |
|
my $out; |
27 |
|
foreach my $v (@_) { |
28 |
|
$v =~ s/($escape_re)/$escape{$1}/g; |
29 |
|
$out .= $v; |
30 |
|
} |
31 |
|
return $out; |
32 |
|
} |
33 |
|
|
34 |
my $spelling_alt; |
my @spellings; |
35 |
# FIX: doesn't work very well |
# FIX: doesn't work very well |
36 |
if ($config->{findaffix}) { |
if ($config->{findaffix}) { |
37 |
$spelling_alt = new Lingua::Spelling::Alternative; |
foreach my $findaffix (split(/[, ]+/,x($config->{findaffix}))) { |
38 |
$spelling_alt->load_findaffix(x($config->{findaffix})); |
my $spelling_alt = new Lingua::Spelling::Alternative; |
39 |
|
$spelling_alt->load_findaffix($findaffix); |
40 |
|
push @spellings,$spelling_alt; |
41 |
|
} |
42 |
} |
} |
43 |
if ($config->{affix}) { |
if ($config->{affix}) { |
44 |
$spelling_alt = new Lingua::Spelling::Alternative; |
foreach my $affix (split(/[, ]+/,x($config->{affix}))) { |
45 |
$spelling_alt->load_affix(x($config->{affix})); |
my $spelling_alt = new Lingua::Spelling::Alternative; |
46 |
|
$spelling_alt->load_affix($affix); |
47 |
|
push @spellings,$spelling_alt; |
48 |
|
} |
49 |
} |
} |
50 |
|
|
51 |
my $hits=0; |
my $hits=0; |
56 |
$labels{$_->{value}} = x($_->{content}); |
$labels{$_->{value}} = x($_->{content}); |
57 |
} |
} |
58 |
|
|
59 |
|
my $path = param('path'); # limit to this path |
60 |
|
my %path_label; |
61 |
|
my @path_name; |
62 |
|
foreach (@{$config->{paths}->{path}}) { |
63 |
|
|
64 |
|
print STDERR "##: $_->{limit}",x($_->{content}),"\n"; |
65 |
|
push @path_name,x($_->{limit}); |
66 |
|
$path_label{$_->{limit}} = x($_->{content}); |
67 |
|
} |
68 |
|
|
69 |
|
my @properties = split(/\s+/,x($config->{properties})); |
70 |
|
|
71 |
if ($config->{charset}) { |
if ($config->{charset}) { |
72 |
print header(-charset=>x($config->{charset})); |
print header(-charset=>x($config->{charset})); |
73 |
} else { |
} else { |
79 |
print x($config->{text}->{documents}); |
print x($config->{text}->{documents}); |
80 |
print textfield('search'); |
print textfield('search'); |
81 |
print submit(-value=> x($config->{text}->{submit})); |
print submit(-value=> x($config->{text}->{submit})); |
82 |
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); |
83 |
|
print checkbox(-name=>'no_properties', -checked=>0, -label=>($config->{text}->{no_properties})) if (@properties); |
84 |
|
if (@path_name) { |
85 |
|
print br,x($config->{text}->{limit}); |
86 |
|
print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); |
87 |
|
} |
88 |
print end_form,hr; |
print end_form,hr; |
89 |
|
|
90 |
if (param('search')) { |
if (param('search')) { |
100 |
$search =~ s/^\s+//; |
$search =~ s/^\s+//; |
101 |
$search =~ s/\s+$//; |
$search =~ s/\s+$//; |
102 |
|
|
103 |
|
my %words; |
104 |
|
|
105 |
foreach (split(/\s+/,$search)) { |
foreach (split(/\s+/,$search)) { |
106 |
if (m/^([+-])(\S+)/) { |
if (m/^([+-])(\S+)/) { |
107 |
$s.= ($s) ? "and " : ""; |
$s.= ($s) ? "and " : ""; |
108 |
$s.="not " if ($1 eq "-"); |
$s.="not " if ($1 eq "-"); |
109 |
if ($spelling_alt && !param('no_affix')) { |
if (@spellings && !param('no_affix')) { |
110 |
my $w = $2; $w =~ s/[\*\s]+//g; |
my $w = $2; $w =~ s/[\*\s]+//g; |
111 |
$w =~ s/^(['"]*)([^'"]+)(['"]*)/$2/; |
$w =~ s/^(['"]*)([^'"]+)(['"]*)/$2/; |
112 |
$s.="$1(".join("* or ",$spelling_alt->alternatives($w))."*)$3 "; |
my $or=""; |
113 |
|
foreach my $spelling_alt (@spellings) { |
114 |
|
$s.="$or$1(".join("* or ",$spelling_alt->alternatives($w))."*)$3 "; |
115 |
|
$or = "or "; |
116 |
|
} |
117 |
} else { |
} else { |
118 |
$s.="$2* "; |
$s.="$2* "; |
119 |
} |
} |
120 |
} else { |
} else { |
121 |
if ($spelling_alt && !param('no_affix')) { |
if (@spellings && !param('no_affix')) { |
122 |
my $w = $_; $w =~ s/[\*\s]+//g; |
my $w = $_; $w =~ s/[\*\s]+//g; |
123 |
#$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
#$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
124 |
$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
my $or=""; |
125 |
|
foreach my $spelling_alt (@spellings) { |
126 |
|
$s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
127 |
|
$or = "or "; |
128 |
|
} |
129 |
} else { |
} else { |
130 |
$s.="$_* "; |
$s.="$_* "; |
131 |
} |
} |
137 |
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
138 |
$s=~s/\*\*+/*/g; |
$s=~s/\*\*+/*/g; |
139 |
|
|
140 |
|
# limit to some path |
141 |
|
$s = "swishdocpath=(\"*$path*\") and $s" if ($path); |
142 |
|
|
143 |
my %params; # optional parametars for swish |
my %params; # optional parametars for swish |
144 |
|
|
145 |
my @properties = split(/\s+/,x($config->{properties})); |
# default format for output |
146 |
$params{properties} = \@properties if (@properties); |
my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n"; |
147 |
|
|
148 |
|
if (@properties) { |
149 |
|
$hit_fmt = x($config->{hit}) if (! param('no_properties')); |
150 |
|
$params{properties} = \@properties; |
151 |
|
} else { |
152 |
|
$hit_fmt = x($config->{hit}) if (x($config->{hit})); |
153 |
|
} |
154 |
|
|
155 |
my $sh = SWISH->connect('Fork', |
my $sh = SWISH->connect('Fork', |
156 |
prog => x($config->{prog}), |
prog => x($config->{prog}), |
158 |
results => sub { |
results => sub { |
159 |
my ($sh,$hit) = @_; |
my ($sh,$hit) = @_; |
160 |
|
|
|
my $hit_fmt = x($config->{hit}) || |
|
|
"<a href=\"%s\">%s</a> [%s]<br>\n"; |
|
|
|
|
161 |
if ($config->{url}) { |
if ($config->{url}) { |
162 |
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)); |
163 |
} else { |
} else { |
164 |
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) ); |
165 |
|
|
166 |
} |
} |
167 |
|
|
178 |
|
|
179 |
$hits = $sh->query($s); |
$hits = $sh->query($s); |
180 |
|
|
181 |
if ($hits > 0) { |
if ($hits && $hits > 0) { |
182 |
print p,hr; |
print p,hr; |
183 |
printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); |
printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); |
184 |
} else { |
} else { |