Skip to main content.
home | support | download

Back to List Archive

Re: minor issue with swish.cgi

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Fri Jun 24 2005 - 13:42:40 GMT
On Fri, Jun 24, 2005 at 03:30:57AM -0700, Roman Chyla wrote:
> if sending query string without index (without si) and without 
> default_index directive in config file, then swish.cgi
> doesn't set "-f " and set errstr
> 
> but what confused me is the message
> 
> Index file error: Could not open the index file 'index.swish-e': No such 
> file or directory
> 
> it is because the first errstr
> "Please select a source to search"
> was rewritten when running swish-e binary
> 
> I think there might be extra check inside of run_query() and avoid 
> running swish-e if the errstr "Please select a source to search" was 
> set, or something simillar
> 
> maybe ?
> 
> return $self if ($self->errstr =~ "Please select a source");
> 
> or
> 
> return $self if (!$self->swish_command('-f') && ($self->errstr =~ 
> "Please select"));

That's a fix, but not how it really should be done.

There's some problem in the logic in swish.cgi, as you can see.

set_query() returns false when problems are detected.  But the calling
constructor (the SwishQuery->new() method) doesn't check that return
value:

    # Fetch the swish-e query from the CGI parameters
    $self->set_query;

    return $self;


That might be better to do something like:

    # Fetch the swish-e query from the CGI parameters
    return $self if $self->set_query;  # was O.K.

    # set errstr if there was a problem.
    $self->errstr("Failed to set the query") unless $self->errstr;

    return $self;

So, $self is still returned, but an error is flagged in the errstr.


and then in process_request() check for that errstr before running
swish:


    # Create search object and build a query based on CGI parameters
    my $search = SwishQuery->new(
        config    => $conf,
        request   => $request_object,
    );

    # don't search if an error already exists
    unless ( $search->errstr )
    {

        # run the query (run if there's a query)
        $search->run_query;  # currently, results is the just the $search object

        if ( $search->hits ) {
            $search->set_navigation;  # sets links
        }

    }


This is an example of why using exceptions for error processing is a
better way to go.

Let me know if that fixes the problem and doesn't generate new
problems for you.



-- 
Bill Moseley
moseley@hank.org

Unsubscribe from or help with the swish-e list: 
   http://swish-e.org/Discussion/

Help with Swish-e:
   http://swish-e.org/current/docs
   swish-e@sunsite.berkeley.edu
Received on Fri Jun 24 06:42:45 2005