1 # $Id: Resultset.pm,v 1.6 2003-03-03 12:14:27 pop Exp $
3 # Zebra perl API header
4 # =============================================================================
5 package IDZebra::Resultset;
12 use IDZebra::Logger qw(:flags :calls);
13 use Scalar::Util qw(weaken);
15 our $VERSION = do { my @r = (q$Revision: 1.6 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
16 our @ISA = qw(IDZebra::Logger);
20 # -----------------------------------------------------------------------------
21 # Class constructors, destructor
22 # -----------------------------------------------------------------------------
24 my ($proto,$session, %args) = @_;
25 my $class = ref($proto) || $proto;
27 bless ($self, $class);
29 $self->{session} = $session;
30 weaken ($self->{session});
32 $self->{odr_stream} = IDZebra::odr_createmem($IDZebra::ODR_DECODE);
34 $self->{name} = $args{name};
35 $self->{recordCount} = $args{recordCount};
36 $self->{errCode} = $args{errCode};
37 $self->{errString} = $args{errString};
44 return ($self->{recordCount});
48 return ($self->{recordCount});
53 return ($self->{errCode});
58 return ($self->{errCode});
61 # =============================================================================
68 if ($self->{session}{zh}) {
69 my $r = IDZebra::deleteResultSet($self->{session}{zh},
70 0, #Z_DeleteRequest_list,
75 if ($self->{odr_stream}) {
76 IDZebra::odr_reset($self->{odr_stream});
77 IDZebra::odr_destroy($self->{odr_stream});
78 $self->{odr_stream} = undef;
81 delete($self->{session});
83 # -----------------------------------------------------------------------------
85 my ($self, %args) = @_;
87 unless ($self->{session}{zh}) {
88 croak ("Session is closed or out of scope");
90 my $from = $args{from} ? $args{from} : 1;
91 my $to = $args{to} ? $args{to} : $self->{recordCount};
93 my $elementSet = $args{elementSet} ? $args{elementSet} : 'R';
94 my $schema = $args{schema} ? $args{schema} : '';
95 my $recordSyntax = $args{recordSyntax} ? $args{recordSyntax} : '';
97 my $class = $args{class} ? $args{class} : '';
100 my $ro = IDZebra::RetrievalObj->new();
101 IDZebra::records_retrieve($self->{session}{zh},
114 for (my $i=$from; $i<=$to; $i++) {
115 my $rec = IDZebra::RetrievalRecord->new();
116 IDZebra::record_retrieve($ro, $self->{odr_stream}, $rec, $i-$from+1);
124 IDZebra::odr_reset($self->{odr_stream});
129 # ============================================================================
131 my ($self, $sortspec, $setname) = @_;
133 unless ($self->{session}{zh}) {
134 croak ("Session is closed or out of scope");
138 $_[0] = $self->{session}->sortResultsets($sortspec,
139 $self->{name}, ($self));
142 return ($self->{session}->sortResultsets($sortspec,
147 # ============================================================================
152 IDZebra::Resultset - Representation of Zebra search results
158 printf ("RS Status is %d (%s)\n", $rs->errCode, $rs->errString);
160 my @recs = $rs->records(from => 1,
165 The I<Resultset> object represents results of a Zebra search. Contains number of hits, search status, and can be used to sort and retrieve the records.
169 The folowing properties are available, trough object methods and the object hash reference:
175 The error code returned from search, resulting the Resultset object.
179 The optional error string
183 The number of hits (records available) in the resultset
187 Just the synonym for I<recordCount>
191 =head1 RETRIEVING RECORDS
193 In order to retrieve records, use the I<records> method:
195 my @recs = $rs->records();
197 By default this is going to return an array of IDZebra::RetrievalRecord objects. The possible arguments are:
203 Retrieve records from the given position. The first record corresponds to position 1. If not specified, retrieval starts from the first record.
207 The last record position to be fetched. If not specified, all records are going to be fetched, starting from position I<from>.
211 The element set used for retrieval. If not specified 'I<R>' 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).
215 The schema used for retrieval. The default is "".
217 =item B<recordSyntax>
219 The record syntax for retrieval. The default is SUTRS.
233 Peter Popovics, pop@technomat.hu
237 IDZebra, IDZebra::Data1, Zebra documentation