Skip to main content.
home | support | download

Back to List Archive

Re: swish.cgi question

From: <moseley(at)>
Date: Sat Oct 18 2003 - 18:15:18 GMT
Hi Aron,

In-Reply-To: <>

> I would like to create a new variable like <TMPL_VAR
> QUERY_SIMPLE> but I want the variable to be something I create
> from the QUERY_SIMPLE variable. For example, if the query is
> "gifts for christmas", I want to be able to create a different
> variable like "gifts+for+christmas" and have it show up in the
> final html template where I put in <TMPL_VAR
> MY_NEW_QUERY_VARIABLE> . I have been searching for where to do
> this in the code for a long time, but have had little luck.

I see you are using "+", is that so you can use this new variable in a 
link?  If so there should already be a variable that you can use for 
that.  I think it's called QUERY_HREF.

> Basically, I need to know where the "$query" variable is, where
> it can be manipulated to make another variable, and where/how
> this information can be passed through
> into the final html shown to the browser. Where is the variable
> that becomes QUERY_SIMPLE?

If I understand correctly, you would do it in the module.  Those Template* modules translate the 
object passed from swish.cgi into something that the given template 
system uses.

Take a look at the (tiny) module.  Then try a search
using that template module to see what data swish.cgi passes in.  That
should give you an idea of what data you have available.  Note: You have
to use query in the URL for that module swish.cgi?query=foo because
there's no input form.

Then you can edit the as you need and add new 

> With this information, I hope to take the $query (the words used
> in the search), do things with it, like run a spell checker, make
> different variables, and put them on the results page with the
> templating system.

To do that correctly you would do it in swish.cgi so all the templating 
modules had access to the data.  But it might be easier just to add it 
to the template module you are using.

For example, to do a spell checker I'd probably use the "parsed_query"
variable (it's broken down by metaname).  I don't think there's a method 
call to fetch that variable but you can just break the OO rules and 
access it directly from the object's hash:  That is 

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

(yes, not very well thought-out design)

Write the spell checker as a separate module and use it from within the
template module.  You might look at the Text::Aspell Perl module on
CPAN.  Might be a good idea to build your dictionary from the swish-e
index so when spell checking you are providing suggestions that are
actually in your index.  Try to avoid HTML in the code and leave that 
to the template where possible.

BTW - If you are not too dependent on HTML::Template, I'd suggest
looking at Template-Toolkit.  I find it has the right mix of power and
code separation.

Bill Moseley
Received on Sat Oct 18 18:15:29 2003