Skip to main content.
home | support | download

Back to List Archive

Re: More Highlighting Colors

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Sat Dec 27 2003 - 15:42:46 GMT
On Sat, Dec 27, 2003 at 01:09:15AM -0800, Frank Naude wrote:
> Hi,
> 
> I would like to highlight different words/phrases with different
> background colors. Swish-e currently only supports one color
> ($highlight_on and $highlight_off in swish.cgi). 
> 
> Any suggestions will be highly appreciated.

Depends on the highlighting module because the work differently.  Some
work with phrases and others don't, and some scan the document
(property) word-by-word and others uses a regular expression.

In all cases, an array of phrases (and array of arrays) is passed to the 
highlighting module.  So, I'd probably create some map of colors based 
on the search phrases.

In scalar form perl returns a string address for a reference

  $ perl -le 'print \$x'
  SCALAR(0x8171850)

so you can actually use that for a hash key.  Create the hash in the 
swish.cgi highlight_props() method.  It would take some reorganization, 
so change:

    $self->{parsed_query} ||= ( parse_query( $parsed_words ) || return );

to something like:

    unless ( $self->{parsed_query} ) { # do we have list of phrases yet?
        $self->{parsed_query} = parse_query( $parsed_words ) || return;
        # setup colors for each phrase
        $highlight_settings->{highlight_color} = 
                get_colors(  $self->{parsed_query} );
    }

I'll leave the get_colors() function up to you.   $self->{parsed_query} 
returns a hash keyed by metaname where each value is an array of arrays 
(array of individual phrases where each phrase is an array of words).
Data::Dumper is your friend.


Then in (for example) PhraseHighlight.pm in this loop "$phrase" is a
reference to an array so you could use its address to lookup the colors:

        foreach my $phrase ( @$phrase_list ) {
            $On  = $settings->{highlight_color}{$phrase}{on};
            $Off = $settings->{highlight_color}{$phrase}{off};

Again, how you do this will depend on the individual highlighting 
module.




-- 
Bill Moseley
moseley@hank.org
Received on Sat Dec 27 15:42:54 2003