Skip to main content.
home | support | download

Back to List Archive

Re: thank you and query parser

From: Jonas Wolf <JOWOLF(at)>
Date: Wed Sep 15 2004 - 07:39:27 GMT
Ok, here is a quick guide how to use it. Note that none of this is 
optimised for mod_perl, which would make a lot of sense to do if you have 
mod_perl. This code assumes you got a $query from a form or something, and 
want to search some index using SWISH::API, using my query parser to parse 
and transform the query.

# generate parser object
my $parser = QueryParser->new;

# parse $query
if ($parser->parse($query))
  # tell the parser which meta names you've got
  # If $query is 'a', then this will tell the parser to generate 'a OR 
all=a OR my=a OR metanames=a'
  $parser->metaNames(qw/swishdefault all my metanames/);
  # get the parser to generate a SWISH::API compatible query string
  my $parsedquery = $parser->formSwishQuery();
  # create swish object
  my $swish = SWISH::API->new("myindex");
  die "Failed to create SWISH::API object" unless $swish;
  $swish->AbortLastError if $swish->Error;

  my $search = $swish->New_Search_Object;
  # execute query
  my $results = $search->Execute($query);
  # ...
  # get the parser error message and die
  die $parser->getLastError();

Received on Wed Sep 15 00:39:45 2004