Skip to main content.
home | support | download

Back to List Archive

Re: MetaName searching in new API

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Tue Mar 04 2003 - 17:05:44 GMT
On Mon, 3 Mar 2003, J Robinson wrote:

> Hello Bill:
> I got a recent dev copy working
> (swish-e-2.3.4-2003-03-01.tar.gz) and I also have the
> same problem as Thomas R. Bruce reports -- all
> property searches that work from the swish-e
> executable return "Unknown metaname" from my
> SWISH::API perl client. Here's examples: Can you let
> me know the status of bugfixes?

Sure.  The problem is your script test script:


> my $query = join(" ", map{qq{'$_'}} @ARGV);
> print "Querying for $query...\n";

$ perl f.pl meta=foo    
Querying for 'meta=foo'...

This is a tricky one.  You are asking swish for the metaname 

    'meta

notice the leading quote?

What you want is:

   my $query = join ' ', @ARGV;

Metanames are delimited only by white space or the "=" sign.
WordCharacters settings does not apply to the meta name.

If you changed your error reporting line to:

 print "Error #$error, " .  $handle->ErrorString() . "\n";

you would see:

$ perl f.pl foo=bar
Querying for 'foo=bar'...
No Results.
err: Unknown metaname: ''foo'
.

which shows the extra quote.


Other comments:

> my $handle = SWISH::API->new($index)
>     || die "Couldn't open $index";

That will never work.  $handle is always true.  See the docs.


> my $search = $handle->New_Search_Object( $query );
> my $results = $search->Execute(  );

The short cut is to do:

   my $results = $handle->Query( $query );

There's a tiny bit of work involved in creating the "search" (probably not
enough to notice) but the idea is you can do:


  my $search = $handle->New_Search_Object;
  # make adjustments to the $search object then later in a loop:

  ...
  while (my $query = get_query_input() ) {

     my $results = $search->Query( $query );
     show_resutls( $results );
  }


> my $num_results = $results->Hits();
> if ( $num_results <= 0 ) {
>     my $error = $handle->Error( );
>     print ($num_results ? "$error\n" : "No
> Results.\n");
>     if ($error && $error != -253) {
>        print "Error #$error, " . $handle->ErrorString() . "\n";
>        exit(1);
>     }
> }

My suggestion would be to not use the error number as they may change.
Again, look at the example in docs.  You are safer doing:

   # do some operation

   if ( $swish->Error ) {
      # something happened - print the error.

      $swish->AbortLastError if $swish->CriticalError;

      print "Error: " . $swish->ErrorString . " " . $swish->LastErrMsg;
      return;
   }

> my $cnt = 0;
> while ( (my $res = $results->NextResult) &&
> (++$cnt < $num)) {
>     printf "%4d ", $res->Property( "swishrank")
>         if $rankshow;
>     printf "%-20s (%s) %s",
>          $res->Property( "swishtitle" ),
>          $res->Property( "namesection" ),
>          $res->Property( "namedesc" );
>     printf " %s", $res->Property( "swishdocpath" )
>         if $fileshow;
>     print "\n";
> }

If $res->Property( 'foo' ) might return undefined for some records then
you can do something like

    $res->Property( 'foo' ) || ''

to avoid warnings.


-- 
Bill Moseley moseley@hank.org
Received on Tue Mar 4 17:06:15 2003