Skip to main content.
home | support | download

Back to List Archive

Re: Returning Highlighted Text or the META Description

From: <Jeffrey.Grunstein(at)not-real.ny.frb.org>
Date: Mon Jan 06 2003 - 21:20:41 GMT
OK, thanks.  I am working with a copy of TemplateDefault.pm that I had
already customized to
do other things.  I am usng PhraseHighlighting.

Below is part of my show_result() function from TemplateDefault.
I try reading in all the metanames using this line: my $metanames
= $results->config('metanames');
But I'm not sure how to go about extracting the description from there,
though.

As a test, I can successfully display "No description found" in my search
results if the search doesn't match in swishdefault.
I think I need to do something like this:
    my $description = '';
    if ( $description_prop ) {
        $description = $this_result->{ $description_prop } ||
$this_result->{ $metanames{description} };

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
but I get an error, about "Global symbol "%metanames" requires explicit
package name at ..."

Here is my metanames line from .swishcgi.conf:
 metanames       => [qw/all swishdefault swishtitle swishdocpath
description keywords/],

And below is the beginning of my show_result() function.
Thanks again for all your help.

***************************************************************************************************
sub show_result {
    my ($results, $this_result ) = @_;

    my $conf = $results->{conf};

    my $DocTitle = $results->config('title_property') || 'swishtitle';

    my $title = $this_result->{$DocTitle} || $this_result->{swishdocpath}
|| '?';

    my $name_labels = $results->config('name_labels');
    my $metanames = $results->config('metanames');


    # The the properties to display

    my $props = '';

    my $display_props = $results->config('display_props');
    if ( $display_props ) {
        $props = join "\n",
            '<br><table cellpadding="0" cellspacing="0"><tr>',
            map ( {
                '<td><font face="verdana, arial, helvetica, sans-serif"
size="1">'
                . ( $name_labels->{$_} || $_ )
                . ': <b>'
                . $this_result->{$_}
                . '</b>&nbsp;&nbsp;&nbsp;'
                . '</font></td>'
                 }  @$display_props
            ),
            '</tr></table>';
    }

    my $description_prop = $results->config('description_prop');

    my $description = '';
    if ( $description_prop ) {
        $description = $this_result->{ $description_prop } || 'No
description found.';
    }


                                                                                                                                              
                    Bill Moseley                                                                                                              
                    <moseley@hank.       To:     Jeffrey.Grunstein@ny.frb.org                                                                 
                    org>                 cc:     Multiple recipients of list <swish-e@sunsite.berkeley.edu>                                   
                                         Subject:     Re: [SWISH-E] Returning Highlighted Text or the META Description                        
                    01/06/2003                                                                                                                
                    10:01 AM                                                                                                                  
                                                                                                                                              
                                                                                                                                              




On Mon, 6 Jan 2003 Jeffrey.Grunstein@ny.frb.org wrote:

>
> Not quite.
>
> I want to display swishdescription if the match was found in
> swishdescription (the BODY tag in this case).
>
> But if the match was found somewhere else (let's say a KEYWORDS or
> DESCRIPTION meta tag), causing
> swishdescription not to be displayed, then display the META_DESCRIPTION
tag
> INSTEAD OF the highlighted
> BODY tag.
>
> In other words, when the search results are displayed, if
swishdescription
> is blank (it would be in the case I describe
> above), set swishdescription to the description meta tag and print that
> instead of what's stored by the STOREDESCRITION
> directive.

Hum, well I'm still not 100% clear.  But I don't think that's the way the
script works.  But it would not be that hard to make it do what you want
to do.  You need a clear understanding of how the script works, though.

swish.cgi works like this:

The record display format is in three parts:
1) the title line that's a link
2) a description
3) additional properties that display as key: value data

This is not hard wired, but the general design works this way.

The parameters in swish.cgi allow you to say what properties each of those
are.  Here's are the settings used for those three and their defaults:

   title_property => 'swishtitle',
   description_prop    => 'swishdescription'
   display_props   => [qw/swishlastmodified swishdocsize swishdocpath/]

Hopefully that should be clear in the comments of swish.cgi.


Now, if you have metanames setup, you can search different fields.

   metanames       => [qw/swishdefault swishtitle swishdocpath /],

That will give you radio buttons to select where you want to search.

Now, for display purposes (really for highlighting purposes) you have to
map the metanames to property names -- they are not related as far as
swish-e knows, but the need to be related for the display.

That is, if you do a normal non-metaname search, you are searching in the
body and title -- so the highlighting code needs to know that there was a
hit in the swishdescription (body) and/or swishtitle (title) properties.
So there's this config setting:

         meta_to_prop_map => {
             swishdefault    => [ qw/swishtitle swishdescription/ ],
             swishtitle      => [ qw/swishtitle/ ],
             swishdocpath    => [ qw/swishdocpath/ ],
             all             => [ qw/swishtitle swishdescription
swishdocpath/ ],
         },

So you can see a search in "swishdefault" means to highlight in the
swishtitle and/or swishdescription:

             swishdefault    => [ qw/swishtitle swishdescription/],

Now, what happens next depends on what highlighting backend module you are
using.  Each result returned from swish-e is passed through the
highlighting code, and that code knows what metaname(s) were searched, and
then uses that meta_to_prop_map hash to highlight words in the *related*
properties.  Some highlighting modules highlight all the words and shows
the entire description, some (like the default 'PhraseHighlight' module)
extracts out a few words on each side of a highlighted word.
'PhraseHighlight' will also only display the first 100 words of the
description if it was *not* what was being searched.

"Display" is the wrong word there.  The displaying is left to the
templating code.

After swish-e has returned all the results, and the highlighting code has
filtered all the display properties, then the templating code decides how
to display the record.

Now, the current default setup for swish.cgi is to display the records in
that fixed format I described above.  If you wanted a system where what
was displayed depends on what metanames were searched, then you will need
to write your own template module -- or maybe just add some logic to the
template if using Template-Toolkit.

To do that (and this is describe a little in the docs) you copy an
existing template module and edit it for your needs.

Again, if you are using Template-Toolkit you could proably do everything
right in the HTML template and not need to write any new perl code.  TT is
a powerful temmplating system.  Since we are talking about display issues
it really makes sense for the template to decide how to format the search
results.

If you are using the default 'TemplateDefault' template system then copy
the TemplateDefault.pm perl module an edit it as needed.

There's a module called TemplateDumper.pm that's purpose is to dump out
the data that swish.cgi passes to the templating modules -- this will show
you what data you can work with.


--
Bill Moseley moseley@hank.org
Received on Mon Jan 6 21:20:57 2003