Skip to main content.
home | support | download

Back to List Archive

Re: output_format FIELDS not working in SWISH.pm

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Wed May 16 2001 - 14:41:25 GMT
At 12:15 AM 05/16/01 -0700, Philip Mak wrote:

Hi Philip,

[You might want to check your connectivity -- I can connect to your mail
server from some paths, but not from others.  It's been like that for days.]


>I have a website that uses SWISH to perform a search in the back end. My
>code is doing this:
>
>my $sh = SWISH->connect('Fork',
>  prog       => '/usr/qd/software/swish/swish-e',
>  indexes    => '/usr/qd/software/swish/sql.dat',
>  output_format => {
>    FIELDS => [qw/swishdocpath subject/],
>    FORMAT => {}
>  },
>  results    => sub {
>    my ($sh, $hit) = @_;
>    push(@hits, $hit->swishdocpath);
>print "TEST: ".$hit->subject."<br>";
>  }
>);

>When I run the code, $hit->swishdocpath is inserted into @hits correctly,
>but $hit->subject always comes out blank.

Did you forget to add this to your swish config file:

   PropertyNames subject

swishdocpath is an "internal" property, and is always available.  subject
is one you must define with PropertyNames.

By the way: If you are not specifying a format, you can replace 

>  output_format => {
>    FIELDS => [qw/swishdocpath subject/],
>    FORMAT => {}
>  },

with:

   properties => [qw/subject/],

The point of output_format is if you want swish to format your data instead
of doing it in your perl program.


Some debugging tips for everyone:

o index a single file
o use -v 9 when indexing to watch the words get added.
o use -D -v 4 -f index | grep -v ^0 to look at how swish indexed the
  single file.  In this case you could have seen that the index was
  not storing the property.
o run swish from the command line with testing something like this.
  In this case you are using a module to run swish, so it's helpful
  to isolate where the problem (module or in swish).

And when posting for help, post (all cut-n-paste to avoid errors):
1) the doc you are indexing
2) the config file you are using
3) the command and its output for indexing
4) the command to run swish and its output showing what's wrong.
5) output of swish-e -V

The idea is that people can cut-n-paste from your email and easily
reproduce your problem:

For example:

> cat c
IndexContents XML .xml
propertynames subject title

> cat t.xml
<title>thetitle</title>
<subject>thesubject</subject>
hello

> ./swish-e -c c -i t.xml -v 0
Indexing Data Source: "File-System"

> ./swish-e -w hello -p subject title -H 0
1000 t.xml "t.xml" 60 "thesubject" "thetitle"

Ok, so we know swish is working.  Let's try the module:

> cat t.pl
use SWISH;
my $sh = SWISH->connect('Fork',
  prog       => './swish-e',
  indexes    => './index.swish-e',
  properties => [qw/title subject/],
  results    => sub {
    my ($sh, $hit) = @_;
    print "Test $_: ", $hit->$_(),"\n"
        for qw/swishdocpath title subject/;
  }
);
print "Total hits: ", $sh->query('hello'),"\n";


> perl t.pl
Test swishdocpath: t.xml
Test title: thetitle
Test subject: thesubject
Total hits: 1

> ./swish-e -V
SWISH-E 2.1-dev-21

Bill Moseley
mailto:moseley@hank.org
Received on Wed May 16 14:43:35 2001