X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=perl%2Flib%2FIDZebra%2FResultset.pm;h=80fabdbf8a95e24012932d0659f4c0c6c317aedc;hb=c45742c694d4fa704d4282ada62c7f46c69fea88;hp=d964e2dbcb8966849dd89141c92458129feab104;hpb=5981b70de0f2d78207ec598384a4b7915c012da9;p=idzebra-moved-to-github.git diff --git a/perl/lib/IDZebra/Resultset.pm b/perl/lib/IDZebra/Resultset.pm index d964e2d..80fabdb 100644 --- a/perl/lib/IDZebra/Resultset.pm +++ b/perl/lib/IDZebra/Resultset.pm @@ -1,4 +1,4 @@ -# $Id: Resultset.pm,v 1.5 2003-03-03 00:45:37 pop Exp $ +# $Id: Resultset.pm,v 1.8 2003-03-05 13:55:22 pop Exp $ # # Zebra perl API header # ============================================================================= @@ -12,7 +12,7 @@ BEGIN { use IDZebra::Logger qw(:flags :calls); use Scalar::Util qw(weaken); use Carp; - our $VERSION = do { my @r = (q$Revision: 1.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + our $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; our @ISA = qw(IDZebra::Logger); } @@ -60,9 +60,18 @@ sub errString { # ============================================================================= sub DESTROY { - my ($self) = @_; + my $self = shift; +# print STDERR "Destroy RS\n"; # Deleteresultset? + + my $stats = 0; + if ($self->{session}{zh}) { + my $r = IDZebra::deleteResultSet($self->{session}{zh}, + 0, #Z_DeleteRequest_list, + 1,[$self->{name}], + $stats); + } if ($self->{odr_stream}) { IDZebra::odr_reset($self->{odr_stream}); @@ -70,14 +79,15 @@ sub DESTROY { $self->{odr_stream} = undef; } -# delete($self->{ro}); -# delete($self->{session}{resultsets}{$self->{name}}); delete($self->{session}); } # ----------------------------------------------------------------------------- sub records { my ($self, %args) = @_; + unless ($self->{session}{zh}) { + croak ("Session is closed or out of scope"); + } my $from = $args{from} ? $args{from} : 1; my $to = $args{to} ? $args{to} : $self->{recordCount}; @@ -120,9 +130,14 @@ sub records { # ============================================================================ sub sort { my ($self, $sortspec, $setname) = @_; + + unless ($self->{session}{zh}) { + croak ("Session is closed or out of scope"); + } + unless ($setname) { - $_[0] = $self->{session}->sortResultsets($sortspec, - $self->{name}, ($self)); + return ($_[0] = $self->{session}->sortResultsets($sortspec, + $self->{session}->_new_setname, ($self))); return ($_[0]); } else { return ($self->{session}->sortResultsets($sortspec, @@ -139,20 +154,92 @@ IDZebra::Resultset - Representation of Zebra search results =head1 SYNOPSIS + $count = $rs->count; + + printf ("RS Status is %d (%s)\n", $rs->errCode, $rs->errString); + + my @recs = $rs->records(from => 1, + to => 10); + =head1 DESCRIPTION The I object represents results of a Zebra search. Contains number of hits, search status, and can be used to sort and retrieve the records. =head1 PROPERTIES - $count = $rs->count; +The folowing properties are available, trough object methods and the object hash reference: - printf ("RS Status is %d (%s)\n", $rs->errCode, $rs->errString); +=over 4 + +=item B + +The error code returned from search, resulting the Resultset object. + +=item B + +The optional error string -I<$rs-EerrCode> is 0, if there were no errors during search. +=item B + +The number of hits (records available) in the resultset + +=item B + +Just the synonym for I + +=back =head1 RETRIEVING RECORDS +In order to retrieve records, use the I method: + + my @recs = $rs->records(); + +By default this is going to return an array of IDZebra::RetrievalRecord objects. The possible arguments are: + +=over 4 + +=item B + +Retrieve records from the given position. The first record corresponds to position 1. If not specified, retrieval starts from the first record. + +=item B + +The last record position to be fetched. If not specified, all records are going to be fetched, starting from position I. + +=item B + +The element set used for retrieval. If not specified 'I' is used, which will return the "record" in the original format (ie.: without extraction, just as the original file, or data buffer in the update call). + +=item B + +The schema used for retrieval. The default is "". + +=item B + +The record syntax for retrieval. The default is SUTRS. + +=back + +=head1 SORTING + +You can sort resultsets by calling: + + $rs1->sort($sort_expr); + +or create a new sorted resultset: + + $rs2 = $rs1->sort($sort_expr); + +The sort expression has the same format as described in the I documentation. For example: + + $rs1->sort('1=4 id'); + +will sort thr results by title, in a case insensitive way, in descending order, while + + $rs1->sort('1=4 a'); + +will sort ascending by titles. =head1 COPYRIGHT @@ -164,6 +251,6 @@ Peter Popovics, pop@technomat.hu =head1 SEE ALSO -IDZebra, IDZebra::Data1, Zebra documentation +Zebra documentation, IDZebra::ResultSet, IDZebra::RetrievalRecord manpages. =cut