Skip to main content.
home | support | download

Back to List Archive

Re: How can i change the search out put formats

From: Peter Karman <peter(at)not-real.peknet.com>
Date: Wed Mar 02 2005 - 14:48:34 GMT
If you are having trouble with search.cgi, I suggest using swish.cgi instead. 
They're both included in the distribution. search.cgi is intended as an example 
for programmers. swish.cgi is supposed to be relatively easy to use for the 
non-programmer.

If you are using swish.cgi, there is a section in the script like this:

         # The 'template' setting defines what generates the output
         # The default is "TemplateDefault" which is reasonably ugly,
         # but does not require installation of a separate templating system.

         # Note that some of the above options may not be available
         # for templating, as it's up to you to layout the form
         # and swish-e results in your template.

I use the HTML::Template version, which is indicated with the .tmpl extension. 
So my relevant code is here:

          template => {
             package         => 'SWISH::TemplateHTMLTemplate',
             options         => {
                 filename            => 'swish.tmpl',
                 path                => '/usr/local/share/swish-e',
                 die_on_bad_params   => 0,
                 loop_context_vars   => 1,
                 cache               => 1,
             },
         },


You might deduce from those settings that the file you want to modify is in 
/usr/local/share/swish-e/swish.tmpl

That requires that HTML::Template be installed on your system, which you can 
check with:

% perl -MHTML::Template -e 1

and if you get no errors, you're in business. Otherwise, go to CPAN.org or try a 
different templating system.

If you do what I did, using HTML::Template, swish.cgi, etc., you can edit the 
file here:

/usr/local/share/swish-e/swish.tmpl

with any text editor, to make the HTML look however you want. I prefer CSS to 
hardcoding style into the template, so I changed a lot of the tags to add 
'class' attributes, etc.

If all this is beyond you at this point, I'm not sure what else I can offer, 
besides suggesting that perhaps Swish-e is not the best tool for you to use. 
It's intended to be one tool in a suite of tools, not an off-the-shelf google 
replacement.

best of luck.

pek




efrain scribbled on 3/1/05 4:59 PM:
> Hi peter.  Sorry for all!!
> 
> Look, really I'm not a system enggineer and this it's a very difult for me. I
> checked the cgi,  you sent me, but really it's very diferent, and I don't know
> what change for get the format that Please can you check it?
> 
> Thanks for all, I apreciate very much for help.
> 
> efrain
> 
> 
> 
> -
> 
>>see the perldoc in search.cgi for how to set the template path.
>>
>>http://swish-e.org/docs/search.cgi.html
>>
>>here's the template we use for the search results on swish-e.org. It 
>>uses Template Toolkit.
>>
>>==============================================
>>
>><div class="search-page">
>>[%-
>>
>>     page.title = 'Search';
>>
>>     MACRO message(text) BLOCK;
>>         '<div class="search-message">';
>>         text;
>>         '</div>';
>>         page.title = text | html;
>>     END;
>>
>>     USE myurl = url( request.myself, query=request.query,
>>                      metaname=request.metaname, 
>>size=request.pagesize );
>>
>>     result_date = Date;  # set date format for results
>>
>>     UNLESS result;
>>         message( "Must enter a query" );
>>     ELSE;
>>
>>         # Show results
>>
>>         message( result.message ) IF result.message;
>>
>>         IF result.results.size;
>>
>>             SET query_html = request.query | html;
>>             page.title = "[$query_html] $result.results.size results";
>>             PROCESS results_header;
>>             PROCESS next_links;
>>             PROCESS display_results;
>>             PROCESS next_links;
>>         ELSE;
>>             message( "No Results Found" );
>>         END;
>>     END;
>>-%]
>></div>
>>
>>[% BLOCK display_results %]
>>     <div class="search-results">
>>
>>     [% FOREACH item = result.results %]
>>         <div class="search-result">
>>             [% PROCESS show_result %]
>>         </div>
>>     [% END %]
>>     </div>
>>[% END %]
>>
>>[% BLOCK results_header %]
>><div class="search-header">
>>     Results for <b>[% request.query | html %]</b><br />
>>     Showing page [% result.page %]
>>
>>     ([% result.start +1 %] - [% (result.start + result.shown) %] of 
>>[% result.hits %] hits)
>>
>></div>
>>[% END %]
>>
>>[% BLOCK next_links %]
>>     [% IF result.prev %]
>>        <a class="next" href="[% myurl( page=result.prev ) %]">Previous</a>
>>     [% END %]
>>     [% IF result.next %]
>>        <a class="prev" href="[% myurl( page=result.next ) %]">Next</a>
>>     [% END %]
>>[% END %]
>>
>>[% BLOCK show_result %]
>>     [%
>>         SET doc_path    = item.Property('swishdocpath');
>>         SET is_list     = doc_path.match('/archive/');
>>         SET is_devel    = doc_path.match('/devel_docs/');
>>         SET is_docs     = doc_path.match('/docs/');
>>     %]
>>
>>     <div class="search-title">
>>
>>         [% IF is_list %]
>>             <span class='indxtype'>[List Archive]</span>
>>         [% ELSIF is_devel %]
>>             <span class='indxtype'>[Development Docs]</span>
>>         [% ELSIF is_docs %]
>>             <span class='indxtype'>[Docs]</span>
>>         [% END %]
>>
>>         <a href="[% item.Property('swishdocpath') %]">
>>             [%  item.Property('swishtitle') || 'missing title' | 
>>highlight('swishtitle', item ) %]<
>>/a>
>>
>>         <span class="search-rank"> -- rank: <b>[% 
>>item.Property('swishrank') %]</b></span>     </div>
>>
>>     <div class="search-description">
>>         [% item.Property('swishdescription') || "No description" | 
>>highlight('swishdescription', it
>>em) %]
>>     </div>
>>
>>     <div class="search-metadata">
>>         Path: <a href="[% item.Property('swishdocpath') %]">
>>             [% item.Property('swishdocpath') | 
>>highlight('swishdocpath', item ) %]</a><br />         Size: [% 
>>item.Property('swishdocsize') %] bytes<br />         Date: [% 
>>result_date.format( item.Property('swishlastmodified')) %]<br />
>>
>>         [% PROCESS show_list_links IF is_list %]
>>
>>         [% IF is_devel %]
>>             Warning: <b>** Development Documentation **</b>
>>         [% END %]
>>     </div>
>>
>>[% END %]
>>
>>[% BLOCK show_list_links %]
>>
>>     [%
>>         SET name    = item.Property('name');
>>         SET email   = item.Property('email');
>>         SET name_href = myurl( query="name=\"$name\"" );
>>         SET email_href = myurl( query="email=\"$email\"" );
>>     %]
>>
>>         Poster's Name: <a href="[% name_href %]" title="All posts 
>>from this name">[% name | html %] </a><br />         Poster's Email: 
>><a href="[% email_href %]" title="All posts from this email">[% 
>>email | htm l %]</a>
>>
>>[% END %]
>>
>>-- 
>>Peter Karman  .  http://peknet.com/  .  peter(at)not-real.peknet.com
> 
> ------- End of Original Message -------

-- 
Peter Karman  .  http://peknet.com/  .  peter(at)not-real.peknet.com
Received on Wed Mar 2 06:48:35 2005