Skip to main content.
home | support | download

Back to List Archive

Re: Returning Highlighted Text or the META

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Wed Jan 08 2003 - 18:55:25 GMT
[I'm copying back to the list, hope you don't mind]

At 03:18 PM 01/07/03 -0500, you wrote:

>Now, in my swish-e index config file, I index the following metanames:
>MetaNames swishtitle swishdocpath description keywords
>
>And I store the <BODY> tag as a swishdescription (or description_prop in
>swish.cgi) :
>StoreDescription HTML2 <BODY> 100000

If you want to *display* the contents of description or keywords you also
need:

 PropertyNames description keywords


>Furthermore, in my .swishcgi.conf config file (for the swish.cgi script), I
>have the following:
>metanames       => [qw/all swishdefault swishtitle swishdocpath description
>keywords/],

That is telling the swish.cgi script to offer a set of radio buttons for
limiting searches to those metanames.


>meta_groups => {
>       all =>  [qw/swishdefault swishtitle swishdocpath description
>keywords/],
>},

And that's saying, basically, that "all" is an alias for those metanames.
So, as you pointed out, when you search for "foo" in the "all" metaname the
swish.cgi script is creating a query like:

   -w swishdefault=(foo) OR swishtitle=(foo) OR swishdocpath=(foo)
         OR description=(foo) OR keywords=(foo)

As I mentioned before, when you get a hit here swish doesn't tell you where
the word "foo" was found.  You just know it was in one or more of those
metanames.


>So, on my swish.cgi page, I let the user pick the properties to search in.

You mean "metnames" not properties, of course.

>Now, here's what I want to do.
>If "foo" was found in swishdefault, swish.cgi should highlight the word
>"foo" in description_prop.  This works fine.  No problem.
>
>If "foo" was found in swishtitle or swishdocpath, swish.cgi should
>highlight the word "foo" in the title or path displayed in my search
>results.
>This also works, so no problem.
>
>Now, what happens if the word "foo" was found in either the "description"
>or "keywords" metaname (the contents of the HTML META tags that I told
>swish-e to index, in the MetaNmes directive in my index config file)?

IF there are listed as a "display_props" to display, the highlighting
should work.  One problem is that "display_props" is normally used for
short properties like date or path (see the swish-e.org discusson list
search).  So formatting for a long description would not look right.

As you pointed out, if the match is NOT in the swishdescription then the
default highlighting module displays the first 100 words of the description.

But what you would rather have in the output template code:

my $matched_prop;
for my $property ( qw/ swishdescription description keywords / ) {

    next unless words_highlighted_in_prop( $results, $property );

    $matched_prop++; 
    display_description( $property );
    last;
}
display_description( 'swishdescription' )
    unless $matched_prop;

Which displays the first description that matched.

So, the problem is detecting which property matched.  You can do it a
couple of ways.

One way would be to have words_highlighted_in_prop() simply do a regular
expression match for the HTML used in highlighting.  That would be a simple
way.

Another way would be to edit the highlighting code.  In the highlighting
object is a reference to the results object.  And the results object is
passed to the templating module.  So you could have the highlighting code
flag which properties words are found in.  This is a better method but much
more work than just using a regex search.

Not tested, but I think you have the right idea:

So in the TemplateDefault.pm code instead of this:

    my $description_prop = $results->config('description_prop');
    
    my $description = '';
    if ( $description_prop ) {
        $description = $this_result->{ $description_prop } || '';
    }

try something like (not tested):

my $matched_prop = 'swishdescription';  # the default you want to use

for my $property ( qw/ swishdescription description keywords / ) {
    next unless $this_result->{$property} =~ /FFFF99/;
    $matched_prop = $property;
    last;
}

my $description = $this_result->{$match_prop} 
     || $this_result->{description}
     || $this_result->{keywords} || "No match";




-- 
Bill Moseley
mailto:moseley@hank.org
Received on Wed Jan 8 18:55:43 2003