Skip to main content.
home | support | download

Back to List Archive

Re: using DefaultHighlight

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Wed Sep 03 2003 - 05:39:30 GMT
On Tue, Sep 02, 2003 at 09:53:33AM -0700, J Robinson wrote:
> Hello All,
> 
> I'm interested in using the SWISH::DefaultHighlight
> module independently from swish.cgi, but I can't quite
> figure out how to invoke it. The naive and minimal:
> 
>  #!/bin/perl -w
>  use strict;
> 
>  use lib '/usr/local/lib/swish-e/perl';
>  use SWISH::DefaultHighlight;
> 
>  my $text = "some long text here ";
> 
>  my @phrases = qw(some text);
>  my %settings = ();
>  my %headers = ();
> 
>  my $sho = new SWISH::DefaultHighlight( {}, {} );

They expect the swish-e headers, specifically the Wordcharacters is 
needed to know how to detect words.  Look at DefaultHighlight.pm 
set_match_regexp().

>  my $ret = $sho->highlight(\$text, \@phrases, 'swishdescription');

I didn't test, but I think @phrases is an array of arrays.


> Clearly doesn't work. Can someone offer a short
> working example of how to invoke
> SWISH::SimpleHighlight without using it with
> swish.cgi?


#!/bin/perl -w
use strict;
use lib '/usr/local/lib/swish-e/perl';
use SWISH::DefaultHighlight;

my $text = "some long text here ";

my @phrases = (
                  [ 'some' ],
                  [ 'text' ],
);

my %settings = ();
my %headers = (
    wordcharacters => 'abcdefghijklmnopqrstuvwxyz',
);

my $sho = new SWISH::DefaultHighlight( \%settings, \%headers );
my $ret = $sho->highlight(\$text, \@phrases, 'swishdescription');
print $text if $ret;

This would be easier and faster unless you need something special that 
that module does:

for my $word (qw/some text/) {
    $text ~= s[\b($word)\b][<b>$1</b>]ig;
}




-- 
Bill Moseley
moseley@hank.org
Received on Wed Sep 3 05:39:40 2003