| 14 | | my $index = shift; |
|---|
| 15 | | if (!exists($swishes{$index})) { |
|---|
| 16 | | my $swish = $swishes{$index} = SWISH::API->new( $index ); |
|---|
| 17 | | die "$0: index $index could not be opened.\n" unless $swish; |
|---|
| 18 | | print STDERR "Index $index opened\n" if $ENV{TEST_VERBOSE}; |
|---|
| 19 | | } |
|---|
| 20 | | return 1; |
|---|
| | 14 | my $index = shift; |
|---|
| | 15 | if (!exists($swishes{$index})) { |
|---|
| | 16 | my $swish = $swishes{$index} = SWISH::API->new( $index ); |
|---|
| | 17 | die "$0: index $index could not be opened.\n" unless $swish; |
|---|
| | 18 | print STDERR "Index $index opened\n" if $ENV{TEST_VERBOSE}; |
|---|
| | 19 | } |
|---|
| | 20 | return 1; |
|---|
| 32 | | my ($index, $query) = @_; |
|---|
| 33 | | my @r = (); |
|---|
| 34 | | #return @r unless $query; |
|---|
| 35 | | my $swish; |
|---|
| 36 | | eval { |
|---|
| 37 | | if (exists($swishes{$index})) { |
|---|
| 38 | | $swish = $swishes{$index}; |
|---|
| 39 | | } else { |
|---|
| 40 | | #$swish = $swishes{$index} = SWISH::API->new( $index ); |
|---|
| 41 | | die "$0: index $index was not opened.\n"; |
|---|
| 42 | | } |
|---|
| 43 | | #print STDERR "Searching for $query\n" if $ENV{TEST_VERBOSE}; |
|---|
| 44 | | my $results = $swish->Query( $query ); |
|---|
| 45 | | my @props = map { $_->Name } ($swish->PropertyList( $index ) ); |
|---|
| 46 | | if ($swish->Error()) { |
|---|
| 47 | | #print STDERR "$0: Error searching for $query: " . $swish->ErrorString(); |
|---|
| 48 | | return @r; |
|---|
| 49 | | } |
|---|
| | 32 | my ($index, $query) = @_; |
|---|
| | 33 | my @r = (); |
|---|
| | 34 | #return @r unless $query; |
|---|
| | 35 | my $swish; |
|---|
| | 36 | eval { |
|---|
| | 37 | if (exists($swishes{$index})) { |
|---|
| | 38 | $swish = $swishes{$index}; |
|---|
| | 39 | } else { |
|---|
| | 40 | #$swish = $swishes{$index} = SWISH::API->new( $index ); |
|---|
| | 41 | die "$0: index $index was not opened.\n"; |
|---|
| | 42 | } |
|---|
| | 43 | #print STDERR "Searching for $query\n" if $ENV{TEST_VERBOSE}; |
|---|
| | 44 | my $results = $swish->Query( $query ); |
|---|
| | 45 | my @props = map { $_->Name } ($swish->PropertyList( $index ) ); |
|---|
| | 46 | if ($swish->Error()) { |
|---|
| | 47 | #print STDERR "$0: Error searching for $query: " . $swish->ErrorString(); |
|---|
| | 48 | return @r; |
|---|
| | 49 | } |
|---|
| 51 | | while ( my $result = $results->NextResult() ) { |
|---|
| 52 | | my %h; |
|---|
| 53 | | for my $p (@props) { $h{$p} = $result->Property($p); } |
|---|
| 54 | | push(@r, \%h); |
|---|
| 55 | | } |
|---|
| 56 | | }; # end eval{} |
|---|
| 57 | | if ($@) { |
|---|
| 58 | | my $str = "$0: test failed: $@"; |
|---|
| 59 | | if ($swish && $swish->Error()) { |
|---|
| 60 | | $str .= " (" . $swish->ErrorString() . ")"; |
|---|
| 61 | | } |
|---|
| 62 | | } |
|---|
| 63 | | return @r; |
|---|
| | 51 | while ( my $result = $results->NextResult() ) { |
|---|
| | 52 | my %h; |
|---|
| | 53 | for my $p (@props) { $h{$p} = $result->Property($p); } |
|---|
| | 54 | push(@r, \%h); |
|---|
| | 55 | } |
|---|
| | 56 | }; # end eval{} |
|---|
| | 57 | if ($@) { |
|---|
| | 58 | my $str = "$0: test failed: $@"; |
|---|
| | 59 | if ($swish && $swish->Error()) { |
|---|
| | 60 | $str .= " (" . $swish->ErrorString() . ")"; |
|---|
| | 61 | } |
|---|
| | 62 | } |
|---|
| | 63 | return @r; |
|---|