Gossamer Forum
Quote Reply
Highlight mod for Spider
Ok. I am not best programmer around but I got around to get the data field from the search results of the spider to show the keyword, so that a user can actually know they have a good result. This mod will also highlight the keyword searched for.

This mod as to go into Spider.pm located in the Plugins directory.

Here is a copy paste of my code that should be located in "post_search_results"

#### OLD TITLE CODE
#my $title = _clip_length( $href->{Title} || $href->{URL}, $conf->{max_title_length} );
my $description = _clip_length( $href->{Description}, $conf->{max_description_length});

#### OLD DATA CODE
#my $data = _clip_length( $href->{Data}, $conf->{max_data_length});


################### FOR DATA MODIFIED ###########
my($len) = ($conf->{max_data_length} / 2) + 1;
my($data) = $href->{Data};
my($highlight) = qq~<span style="background-color: #D2E9FF">~;
my($endhighlight) = qq~</span>~;

if ($data =~ /(.{0,$len})($query)(.{0,$len})/) {

my($start) = $1;
my($end) = $3;
my($query1) = $2;

if (length($start) == $len) { $start =~ s/^./.../; }
if (length($end) == $len) { $end =~ s/.$/.../; }


$data = $start . $query1 . $end;
$data =~ s/$query1/$highlight$query1$endhighlight/g;

}
else {
$data = _clip_length( $href->{Data}, $conf->{max_data_length});
$data =~ s/$query/$highlight$query$endhighlight/g;
}
################### FOR DATA MODIFIED ###########

################### FOR TITLE MODIFIED ###########
$len = ( $conf->{max_title_length} / 2) + 1;
my($title) = $href->{Title} || $href->{URL};


if ($title =~ /(.{0,$len})($query)(.{0,$len})/) {

my($start1) = $1;
my($end1) = $3;
my($query1) = $2;

if (length($start1) == $len) { $start1 =~ s/^./.../; }
if (length($end1) == $len) { $end1 =~ s/.$/.../; }


$title = $start1 . $query1 . $end1;
$title =~ s/$query1/$highlight$query1$endhighlight/g;
}
else {
$title = _clip_length( $href->{Title} || $href->{URL}, $conf->{max_title_length} );
$title =~ s/$query/$highlight$query$endhighlight/g;
}
################### FOR TITLE MODIFIED ###########


Here is an example from my site.
http://www.uhaaa.com/...=1&query=Sanook!

<EDIT>Forgot to mentioned that my site is in Thai (the language of thailand) If you want to see a real look in thai font how it looks check it out here: http://www.uhaaa.com/spider_mod.jpg</EDIT>

efe.
Any suggestions on making this better are welcome. :)

Quote Reply
Re: Highlight mod for Spider In reply to
Use CSS1 codes, so that the effect is universally accessible across browsers. The background codes will only work in IE...

Also, implement some browser check codes to show different css files...

Regards,

Eliot Lee