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 $spelling_alt; |
35 |
# FIX: doesn't work very well |
# FIX: doesn't work very well |
50 |
$labels{$_->{value}} = x($_->{content}); |
$labels{$_->{value}} = x($_->{content}); |
51 |
} |
} |
52 |
|
|
53 |
|
my $path = param('path'); # limit to this path |
54 |
|
my %path_label; |
55 |
|
my @path_name; |
56 |
|
foreach (@{$config->{paths}->{path}}) { |
57 |
|
push @path_name,x($_->{limit}); |
58 |
|
$path_label{$_->{limit}} = x($_->{content}); |
59 |
|
} |
60 |
|
|
61 |
|
my @properties = split(/\s+/,x($config->{properties})); |
62 |
|
|
63 |
if ($config->{charset}) { |
if ($config->{charset}) { |
64 |
print header(-charset=>x($config->{charset})); |
print header(-charset=>x($config->{charset})); |
65 |
} else { |
} else { |
71 |
print x($config->{text}->{documents}); |
print x($config->{text}->{documents}); |
72 |
print textfield('search'); |
print textfield('search'); |
73 |
print submit(-value=> x($config->{text}->{submit})); |
print submit(-value=> x($config->{text}->{submit})); |
74 |
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); |
75 |
|
print checkbox(-name=>'no_properties', -checked=>0, -label=>($config->{text}->{no_properties})) if (@properties); |
76 |
|
if (@path_name) { |
77 |
|
print br,x($config->{text}->{limit}); |
78 |
|
print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); |
79 |
|
} |
80 |
print end_form,hr; |
print end_form,hr; |
81 |
|
|
82 |
if (param('search')) { |
if (param('search')) { |
119 |
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
120 |
$s=~s/\*\*+/*/g; |
$s=~s/\*\*+/*/g; |
121 |
|
|
122 |
my @properties = split(/\s+/,x($config->{properties})); |
# limit to some path |
123 |
|
$s = "swishdocpath=(\"$path\") and $s" if ($path); |
124 |
|
|
125 |
|
my %params; # optional parametars for swish |
126 |
|
|
127 |
|
# default format for output |
128 |
|
my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n"; |
129 |
|
|
130 |
|
if (@properties) { |
131 |
|
$hit_fmt = x($config->{hit}) if (! param('no_properties')); |
132 |
|
$params{properties} = \@properties if (@properties); |
133 |
|
} else { |
134 |
|
$hit_fmt = x($config->{hit}) if (x($config->{hit})); |
135 |
|
} |
136 |
|
|
137 |
my $sh = SWISH->connect('Fork', |
my $sh = SWISH->connect('Fork', |
138 |
prog => x($config->{prog}), |
prog => x($config->{prog}), |
139 |
indexes => x($config->{index}), |
indexes => x($config->{index}), |
|
properties => \@properties, |
|
140 |
results => sub { |
results => sub { |
141 |
my ($sh,$hit) = @_; |
my ($sh,$hit) = @_; |
142 |
|
|
|
my $hit_fmt = x($config->{hit}) || |
|
|
"<a href=\"%s\">%s</a> [%s]<br>\n"; |
|
|
|
|
143 |
if ($config->{url}) { |
if ($config->{url}) { |
144 |
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)); |
145 |
} else { |
} else { |
146 |
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) ); |
147 |
|
|
148 |
} |
} |
149 |
|
|
152 |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
# print "Field '$_' = '", $hit->$_, "'<br>\n" for sort @fields; |
153 |
}, |
}, |
154 |
maxhits => param('max_hits') || $max_hits, |
maxhits => param('max_hits') || $max_hits, |
155 |
|
\%params, |
156 |
); |
); |
157 |
|
|
158 |
die $SWISH::errstr unless $sh; |
die $SWISH::errstr unless $sh; |
160 |
|
|
161 |
$hits = $sh->query($s); |
$hits = $sh->query($s); |
162 |
|
|
163 |
if ($hits > 0) { |
if ($hits && $hits > 0) { |
164 |
print p,hr; |
print p,hr; |
165 |
printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); |
printf (x($config->{text}->{hits}),$hits,param('max_hits') || $max_hits,$s); |
166 |
} else { |
} else { |