--- trunk/html/swish.cgi 2004/05/22 18:33:33 80 +++ trunk/html/swish.cgi 2004/08/28 22:15:59 81 @@ -9,6 +9,41 @@ use Text::Iconv; use Data::Pageset; + +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 $qm $af"); + $i++; + $i = 0 if ($i > $#colors); + } + } + my $ellip = ' ... '; + my $snippet = $ellip. join($ellip, @snips) . $ellip; + + return $snippet; +} + # for pager my $pages_per_set = 20; @@ -65,7 +100,9 @@ $labels{$_->{value}} = x($_->{content}); } -my $path = param('path'); # limit to this path +my $path; +# limit to this path +$path .= '"'.join('*" or "',param('path')).'*"' if (param('path')); my %path_label; my @path_name; foreach (@{$config->{paths}->{path}}) { @@ -93,6 +130,8 @@ if (@path_name) { print br,x($config->{text}->{limit}); print popup_menu(-name=>'path',-values=>\@path_name,-labels=>\%path_label,-default=>$path); +} elsif (param('path')) { + print hidden(-name=>'path',-values=>param('path')); } print end_form,hr; @@ -147,7 +186,7 @@ $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 @@ -213,10 +252,14 @@ last if (! $result); my @arr; + foreach my $prop (@properties) { if ($prop =~ m/swishdescription/) { - my $tmp = $result->Property($prop); - $tmp =~ s/<[^>]+>//g; + my $tmp = get_snippet( + $result->Property($prop), + split(/\s+/,$search) + ); + push @arr, $tmp; } else { push @arr, $result->Property($prop);