1 # $Id: ScanList.pm,v 1.2 2003-03-05 13:55:22 pop Exp $
3 # Zebra perl API header
4 # =============================================================================
5 package IDZebra::ScanList;
12 use IDZebra::Logger qw(:flags :calls);
13 use IDZebra::ScanEntry;
14 use Scalar::Util qw(weaken);
16 our $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
17 our @ISA = qw(IDZebra::Logger);
21 # -----------------------------------------------------------------------------
22 # Class constructors, destructor
23 # -----------------------------------------------------------------------------
25 my ($proto,$session, %args) = @_;
26 my $class = ref($proto) || $proto;
28 bless ($self, $class);
30 $self->{session} = $session;
31 weaken ($self->{session});
33 $self->{expression} = $args{expression};
34 $self->{databases} = $args{databases};
36 $self->{so} = IDZebra::ScanObj->new();
38 $self->{odr_stream} = IDZebra::odr_createmem($IDZebra::ODR_DECODE);
40 $self->entries(num_entries => 0);
48 if ($self->{odr_stream}) {
49 IDZebra::odr_reset($self->{odr_stream});
50 IDZebra::odr_destroy($self->{odr_stream});
51 $self->{odr_stream} = undef;
55 delete($self->{session});
58 # =============================================================================
61 return ($self->{so}{is_partial});
66 return ($self->{so}{position});
71 return ($self->{so}{num_entries});
76 return ($self->{session}->errCode);
81 return ($self->{session}->errString);
84 # -----------------------------------------------------------------------------
86 my ($self, %args) = @_;
88 unless ($self->{session}{zh}) {
89 croak ("Session is closed or out of scope");
94 $so->{position} = defined($args{position}) ? $args{position} : 1;
95 $so->{num_entries} = defined($args{num_entries}) ? $args{num_entries} : 20;
98 if ($self->{databases}) {
99 @origdbs = $self->{session}->databases;
100 $self->{session}->databases(@{$self->{databases}});
103 $so->{is_partial} = 0;
105 my $r = IDZebra::scan_PQF($self->{session}{zh}, $so,
107 $self->{expression});
109 if ($self->{session}->errCode) {
110 croak ("Error in scan, code: ".$self->{session}->errCode .
111 ", message: ".$self->{session}->errString);
115 for (my $i=1; $i<=$so->{num_entries}; $i++) {
118 IDZebra::ScanEntry->new(entry => IDZebra::getScanEntry($so, $i),
123 if ($self->{databases}) {
124 $self->{session}->databases(@origdbs);
127 IDZebra::odr_reset($self->{odr_stream});
135 # ============================================================================
140 IDZebra::ScanList - Scan results
144 $sl = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a",
145 databases => [qw(demo1 demo2)]);
147 @entries = $sl->entries(position => 5,
158 The scan list object is the result of a scan call, and can be used to retrieve entries from the list. To do this, use the B<entries> method,
160 @entries = $sl->entries(position => 5,
163 returning an array of I<IDZebra::ScanEntry> objects.
164 The possible arguments are:
170 The requested position of the scanned term in the returned list. For example, if position 5 is given, and the scan term is "a", then the entry corresponding to term "a" will be on the position 5 of the list (4th. elment of the array). It may happen, that due to the position of term in the whole index, it's not possible to put the entry on the requested position (for example, the term is on the 2nd position of the index), this case I<$sl-E<gt>position> will contain a different value, presenting the actual position. The default value is 1.
174 The requested number of entries in the list. See I<$sl-E<gt>num_entries> for the actual number of fetched entries. The dafault value is 20.
180 You can reach the following properties as function calls on the IDZebra::ScanList object:
186 After calling I<entries>, the actual position of the requested term.
190 After calling I<entries>, the actual number of entries returned.
194 Only partial list is returned by I<entries>.
204 Peter Popovics, pop@technomat.hu
208 Zebra documentation, IDZebra::Session manpage.