9 |
use Text::Iconv; |
use Text::Iconv; |
10 |
use Data::Pageset; |
use Data::Pageset; |
11 |
|
|
12 |
|
|
13 |
|
sub get_snippet { |
14 |
|
my $context_chars = 100; |
15 |
|
|
16 |
|
my $desc = shift || return ''; |
17 |
|
# test if $desc contains any of our query words |
18 |
|
my @snips; |
19 |
|
|
20 |
|
my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff}; |
21 |
|
|
22 |
|
my $i = 0; |
23 |
|
|
24 |
|
for my $q (@_) { |
25 |
|
if ($desc =~ m/(.*?)(\Q$q\E)(.*)/si) { |
26 |
|
my $bef = $1; |
27 |
|
my $qm = $2; |
28 |
|
my $af = $3; |
29 |
|
$bef = substr $bef, -$context_chars; |
30 |
|
$af = substr $af, 0, $context_chars; |
31 |
|
|
32 |
|
# no partial words... |
33 |
|
$af =~ s,^\S+\s+|\s+\S+$,,gs; |
34 |
|
$bef =~ s,^\S+\s+|\s+\S+$,,gs; |
35 |
|
|
36 |
|
push(@snips, "$bef <span style=\"background:".$colors[$i]."\">$qm</span> $af"); |
37 |
|
$i++; |
38 |
|
$i = 0 if ($i > $#colors); |
39 |
|
} |
40 |
|
} |
41 |
|
my $ellip = ' ... '; |
42 |
|
my $snippet = $ellip. join($ellip, @snips) . $ellip; |
43 |
|
|
44 |
|
return $snippet; |
45 |
|
} |
46 |
|
|
47 |
# for pager |
# for pager |
48 |
my $pages_per_set = 20; |
my $pages_per_set = 20; |
49 |
|
|
100 |
$labels{$_->{value}} = x($_->{content}); |
$labels{$_->{value}} = x($_->{content}); |
101 |
} |
} |
102 |
|
|
103 |
my $path = param('path'); # limit to this path |
my $path; |
104 |
|
# limit to this path |
105 |
|
$path .= '"'.join('*" or "',param('path')).'*"' if (param('path')); |
106 |
my %path_label; |
my %path_label; |
107 |
my @path_name; |
my @path_name; |
108 |
foreach (@{$config->{paths}->{path}}) { |
foreach (@{$config->{paths}->{path}}) { |
130 |
if (@path_name) { |
if (@path_name) { |
131 |
print br,x($config->{text}->{limit}); |
print br,x($config->{text}->{limit}); |
132 |
print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); |
print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); |
133 |
|
} elsif (param('path')) { |
134 |
|
print hidden(-name=>'path',-values=>param('path')); |
135 |
} |
} |
136 |
print end_form,hr; |
print end_form,hr; |
137 |
|
|
186 |
$s=~s/\*\*+/*/g; |
$s=~s/\*\*+/*/g; |
187 |
|
|
188 |
# limit to some path |
# limit to some path |
189 |
$s = "swishdocpath=(\"*$path*\") and $s" if ($path); |
$s = "swishdocpath=($path) and $s" if ($path); |
190 |
|
|
191 |
my %params; # optional parametars for swish |
my %params; # optional parametars for swish |
192 |
|
|
252 |
last if (! $result); |
last if (! $result); |
253 |
|
|
254 |
my @arr; |
my @arr; |
255 |
|
|
256 |
foreach my $prop (@properties) { |
foreach my $prop (@properties) { |
257 |
if ($prop =~ m/swishdescription/) { |
if ($prop =~ m/swishdescription/) { |
258 |
my $tmp = $result->Property($prop); |
my $tmp = get_snippet( |
259 |
$tmp =~ s/<[^>]+>//g; |
$result->Property($prop), |
260 |
|
split(/\s+/,$search) |
261 |
|
); |
262 |
|
|
263 |
push @arr, $tmp; |
push @arr, $tmp; |
264 |
} else { |
} else { |
265 |
push @arr, $result->Property($prop); |
push @arr, $result->Property($prop); |