Search::Z3950::ResultSet - Z39.50 search results


Search-Z3950 documentation Contained in the Search-Z3950 distribution.

Index


Code Index:

NAME

Top

Search::Z3950::ResultSet - Z39.50 search results

SYNOPSIS

Top

    $n = $rs->count;
    $rs->prefetch(1, $n) if $n > 0 and $n <= 20;
    foreach my $i (1..$n) {
        my $rec = $rs->record($i);
        if ($rec->isa('MARC::Record')) {
            my $title = $rec->title;
            my $author = $rec->author;
            ...
        }
        ...
    }

DESCRIPTION

Top

Search::Z3950::ResultSet provides access to the records found in a search using Search::Z3950.

PUBLIC METHODS

Top

new

    $rs = Search::Z3950::ResultSet->new($zrs);

Construct a new Search::Z3950::ResultSet. The single parameter is the Z39.50 result set (an instance of Net::Z3950::ResultSet).

This method should normally be called only by Search::Z3950.

count

    $n = $rs->count;

The number of matching records.

record

    $rec = $rs->record($i);

Retrieve a matching record. This will be a MARC::Record when possible (i.e., when the underlying object returned by Net::3950::ResultSet (Net::3950::ResultSet) isa Net::3950::Record::USMARC (Net::3950::Record::USMARC)); otherwise, it will be an instance of a class in the Net::3950::Record (Net::3950::Record) hierarchy.

The single parameter is the record number, which starts at 1 (not zero).

record throws an error if the record couldn't be fetched (e.g., if the server connection has just been lost).

NOTE: the record numbers start at 1.

Did I mention that the record numbers start at 1?

prefetch

    $rs->prefetch($i, $n);

Pre-fetch records $i to $i+$n-1 (inclusive) from the Z39.50 server. Call this method (before calling record) to reduce the number of record requests sent over the network to the server.

(If you're only interested in the first matching record, it probably makes no difference whether you call prefetch or not.)

Returns a true value if the record(s) were successfully retrieved, or a false value otherwise. The retrieved records are not returned.

(As currently implemented, this method simply invokes the present method on the Search::Z3950 object's Net::Z3950 (Net::Z3950) object.)

PRIVATE METHODS

Top

These methods are for the internal use of Search::Z3950::ResultSet (and its subclasses, if any).

zrs

    $zrs = $rs->zrs;
    $rs->zrs($zrs);

Get or set the Z39.50 result set (an instance of Net::Z3950::ResultSet).

BUGS

Top

None that I know of. You might check http://rt.cpan.org to see if others have reported any bugs.

TO DO

Top

SEE ALSO

Top

Search::Z3950, Net::Z3950::ResultSet, MARC::Record.

AUTHOR

Top

Paul Hoffman <nkuitse AT cpan DOT org>

COPYRIGHT

Top


Search-Z3950 documentation Contained in the Search-Z3950 distribution.

package Search::Z3950::ResultSet;

use strict;

use MARC::Record;

sub new {
    my ($cls, $zrs) = @_;
    bless { 'zrs' => $zrs }, $cls;
}

sub count    { shift->zrs->size        }
sub prefetch { shift->zrs->present(@_) }
sub errcode  { shift->zrs->errcode(@_) }
sub errmsg   { shift->zrs->errmsg(@_)  }
sub addinfo  { shift->zrs->addinfo(@_) }
sub option   { shift->zrs->option(@_)  }

sub record {
	my ($self, $i) = @_;
	die "Invalid record number ($i)"
	    unless defined $i and $i =~ /^\d+$/;
	die "Record numbers begin with 1, not 0"
	    if $i == 0;
	die "Record number ($i) is greater than the number of matches"
	    unless $i <= $self->count;
	my $zrs = $self->zrs;
	my $rec = $zrs->record($i);
	unless (defined $rec) {
	    die sprintf(<<'EOS', $i, $zrs->errcode, $zrs->errmsg, $zrs->addinfo);
Matching record (%s) couldn't be retrieved:
  error code:    %s
  error message: %s
  add'l info:    %s
EOS
	}
	return MARC::Record->new_from_usmarc($rec->rawdata)
	    if UNIVERSAL::isa($rec, 'Net::Z3950::Record::USMARC');
	return $rec;
}

# --- Get or set the underlying Net::Z3950::ResultSet object
sub zrs { scalar(@_) > 1 ? $_[0]->{'zrs'} = $_[1] : $_[0]->{'zrs'} }


1;