8 |
use Lingua::Spelling::Alternative; |
use Lingua::Spelling::Alternative; |
9 |
use Text::Iconv; |
use Text::Iconv; |
10 |
use Data::Pageset; |
use Data::Pageset; |
11 |
|
use FormatResult; |
|
|
|
|
sub get_snippet { |
|
|
my $context_chars = 100; |
|
|
|
|
|
my $desc = shift || return ''; |
|
|
# test if $desc contains any of our query words |
|
|
my @snips; |
|
|
|
|
|
my @colors = qw{#ffff66 #a0ffff #99ff99 #ff9999 #ff66ff}; |
|
|
|
|
|
my $i = 0; |
|
|
|
|
|
for my $q (@_) { |
|
|
if ($desc =~ m/(.*?)(\Q$q\E)(.*)/si) { |
|
|
my $bef = $1; |
|
|
my $qm = $2; |
|
|
my $af = $3; |
|
|
$bef = substr $bef, -$context_chars; |
|
|
$af = substr $af, 0, $context_chars; |
|
|
|
|
|
# no partial words... |
|
|
$af =~ s,^\S+\s+|\s+\S+$,,gs; |
|
|
$bef =~ s,^\S+\s+|\s+\S+$,,gs; |
|
|
|
|
|
push(@snips, "$bef <span style=\"background:".$colors[$i]."\">$qm</span> $af"); |
|
|
$i++; |
|
|
$i = 0 if ($i > $#colors); |
|
|
} |
|
|
} |
|
|
my $ellip = ' ... '; |
|
|
my $snippet = $ellip. join($ellip, @snips) . $ellip; |
|
|
|
|
|
return $snippet; |
|
|
} |
|
12 |
|
|
13 |
# for pager |
# for pager |
14 |
my $pages_per_set = 20; |
my $pages_per_set = 20; |
72 |
my %path_label; |
my %path_label; |
73 |
my @path_name; |
my @path_name; |
74 |
foreach (@{$config->{paths}->{path}}) { |
foreach (@{$config->{paths}->{path}}) { |
|
|
|
|
print STDERR "##: $_->{limit}",x($_->{content}),"\n"; |
|
75 |
push @path_name,x($_->{limit}); |
push @path_name,x($_->{limit}); |
76 |
$path_label{$_->{limit}} = x($_->{content}); |
$path_label{$_->{limit}} = x($_->{content}); |
77 |
} |
} |
104 |
my $s; |
my $s; |
105 |
# re-write query from +/- to and/and not |
# re-write query from +/- to and/and not |
106 |
|
|
107 |
|
my @s_highlite; |
108 |
|
|
109 |
my $search = param('search'); |
my $search = param('search'); |
110 |
my $s_phrase = ""; |
|
111 |
|
# strip spaces |
112 |
|
$search =~ s/^\s+//; |
113 |
|
$search =~ s/\s+$//; |
114 |
|
# fixup search string |
115 |
|
$search=~tr/¹ð¾èæ©Ð®ÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
116 |
|
$search=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
117 |
|
|
118 |
|
# extract phrases and put them first |
119 |
while ($search =~ s/\s*("[^"]+")\s*/ /) { |
while ($search =~ s/\s*("[^"]+")\s*/ /) { |
120 |
$s .= "$1 "; |
$s .= "$1 "; |
121 |
|
push @s_highlite, $1; |
122 |
} |
} |
|
$search =~ s/^\s+//; |
|
|
$search =~ s/\s+$//; |
|
123 |
|
|
124 |
my %words; |
my %words; |
125 |
|
|
138 |
} else { |
} else { |
139 |
$s.="$2* "; |
$s.="$2* "; |
140 |
} |
} |
141 |
|
push @s_highlite, $2 if ($1 ne "-"); |
142 |
} else { |
} else { |
143 |
if (@spellings && !param('no_affix')) { |
if (@spellings && !param('no_affix')) { |
144 |
my $w = $_; $w =~ s/[\*\s]+//g; |
my $w = $_; $w =~ s/[\*\s]+//g; |
|
#$s.="(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
|
145 |
my $or=""; |
my $or=""; |
146 |
foreach my $spelling_alt (@spellings) { |
foreach my $spelling_alt (@spellings) { |
147 |
$s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
$s.="$or(".join("* or ",$spelling_alt->alternatives($w))."*) "; |
150 |
} else { |
} else { |
151 |
$s.="$_* "; |
$s.="$_* "; |
152 |
} |
} |
153 |
|
push @s_highlite, $_; |
154 |
} |
} |
155 |
} |
} |
156 |
|
|
157 |
# fixup search string |
# fix multiple stars |
|
$s=~tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
|
|
$s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; |
|
158 |
$s=~s/\*\*+/*/g; |
$s=~s/\*\*+/*/g; |
159 |
|
|
160 |
# limit to some path |
# limit to some path |
165 |
# default format for output |
# default format for output |
166 |
my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n"; |
my $hit_fmt = "<a href=\"%s\">%s</a> [%s]<br>\n"; |
167 |
|
|
|
# output start of table |
|
|
print qq{ |
|
|
<table border="0"> |
|
|
}; |
|
|
# html before and after each hit |
|
|
my $tr_pre = qq{ |
|
|
<tr><td> |
|
|
}; |
|
|
my $tr_post = qq{ |
|
|
</td></tr> |
|
|
}; |
|
|
|
|
168 |
if (@properties) { |
if (@properties) { |
169 |
$hit_fmt = x($config->{hit}) if (! param('no_properties')); |
$hit_fmt = x($config->{hit}) if (! param('no_properties')); |
170 |
$params{properties} = \@properties; |
$params{properties} = \@properties; |
201 |
} |
} |
202 |
|
|
203 |
my %path2title; |
my %path2title; |
|
use Data::Dumper; |
|
204 |
foreach my $p (@{$config->{path2title}->{path}}) { |
foreach my $p (@{$config->{path2title}->{path}}) { |
205 |
$path2title{$p->{dir}} = $p->{content}; |
$path2title{$p->{dir}} = $p->{content}; |
206 |
} |
} |
207 |
|
|
208 |
|
# output start of table |
209 |
|
print qq{ |
210 |
|
<table border="0"> |
211 |
|
}; |
212 |
|
# html before and after each hit |
213 |
|
my $tr_pre = qq{ |
214 |
|
<tr><td> |
215 |
|
}; |
216 |
|
my $tr_post = qq{ |
217 |
|
</td></tr> |
218 |
|
}; |
219 |
|
|
220 |
for(my $i=$pager->first; $i<=$pager->last; $i++) { |
for(my $i=$pager->first; $i<=$pager->last; $i++) { |
221 |
|
|
222 |
my $result = $results->NextResult; |
my $result = $results->NextResult; |
226 |
|
|
227 |
foreach my $prop (@properties) { |
foreach my $prop (@properties) { |
228 |
if ($prop =~ m/swishdescription/) { |
if ($prop =~ m/swishdescription/) { |
229 |
my $tmp = get_snippet( |
my $tmp = FormatResult::get_snippet( |
230 |
$result->Property($prop), |
e($result->Property($prop)), |
231 |
split(/\s+/,$search) |
@s_highlite, |
232 |
); |
); |
233 |
|
|
234 |
push @arr, $tmp; |
push @arr, $tmp; |