SWISH::API::Remote::Results - Represents the results of a search on a swished server


SWISH-API-Remote documentation Contained in the SWISH-API-Remote distribution.

Index


Code Index:

NAME

Top

SWISH::API::Remote::Results - Represents the results of a search on a swished server

DESCRIPTION

Top

Stores the results of a search from a swished server. Intended to be used with SWISH::API::Remote.

my $results = SWISH::API::Remote::Results->new()

returns a new SWISH::API::Remote::Results object. Normally called by SWISH::API::Remote for you.

my $error = $results->Error();

returns zero if there were no errors reported, non-zero otherwise.

my $error_string = $results->ErrorString();

returns the string representation of the error(s) returned from the swished server.

my $result = $results->NextResult();

returns the next result fetched from the swished server. If there are no more results for our query, returns undef

$results->SeekResults( $row_number );

Arranges for the next result retrieved by NextResult to be the row with the passed number. Rows always start at 0, even when using the BEGIN option to SWISH::API::Remote::Execute().

$results->Hits();

Returns the number of total hits found for the search.

$results->Fetched();

Returns the number of rows fetched for this search.

$results->HeaderNames();

Returns a sorted name keys of the header available for the swish-e results

SEE ALSO

Top

SWISH::API::Remote::Result, SWISH::API::Remote, swish-e

AUTHOR

Top

Josh Rabinowitz, <joshr@localdomain>

COPYRIGHT AND LICENSE

Top


SWISH-API-Remote documentation Contained in the SWISH-API-Remote distribution.

package SWISH::API::Remote::Results;
use SWISH::API::Remote::FunctionGenerator;
use strict;
use warnings;

############################################
use fields qw( results hits errors debugs iterator stopwords );


############################################
# results is a list of SWISH::API::Remote::Result objects,
# hits is an int of the number of hits found by swish-e
# errors is a list of lines
# debugs is a list of debug lines
# iterator is for NextResult() and SeekResult()
sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless( $self, $class );
    $self->{iterator} = 0;
    $self->{results}  = [];
    $self->{errors}   = [];
    $self->{hits}     = 0;
    $self->{stopwords} = '';
    #$self->{headers}   = undef;
    return $self;
}


############################################
sub Error {
    my $self = shift;
    return scalar( @{ $self->{errors} } );
}


############################################
sub ErrorString {
    my $self = shift;
    return join ( "\n", @{ $self->{errors} } ) . "\n";
}


############################################
sub SeekResult {
    my $self = shift;
    $self->{iterator} = shift || 0;
}


############################################
sub NextResult {
    my ($self) = @_;
    my $ret = undef;
    if ( $self->{iterator} < @{ $self->{results} } ) {
        $ret = $self->{results}[ $self->{iterator} ];
        $self->{iterator}++;
    }
    return $ret;
}


############################################
sub Hits {
    my $self = shift;
    if (@_) { $self->{hits} = $_[0] }
    else { return ( $self->{hits} || 0 ) }
}

############################################
sub Fetched {
    my $self = shift;
    exists( $self->{results} ) ? scalar( @{ $self->{results} } ) : 0;
}

############################################ 
sub AddResult {
    my ( $self, $result ) = @_;
    push ( @{ $self->{results} }, $result );
}

############################################ 
sub AddError {
    my ( $self, $error ) = @_;
    push ( @{ $self->{errors} }, $error );
}

############################################ 
sub AddDebug {
    my ( $self, $debug ) = @_;
    push ( @{ $self->{debugs} }, $debug );
}

############################################ 
# for conformance with SWISH::API
# TODO: Code this!!!
sub HeaderNames
{
    my $self = shift;
    my (%h);
    return sort keys %h;
}

############################################ 
# S::A vers 0.04 syntax , according to peknet
sub header_names { return HeaderNames(@_) }

############################################ 
SWISH::API::Remote::FunctionGenerator::makeaccessors(__PACKAGE__,
                                 qw ( results errors stopwords ));


1;
__END__

1;